1 solutions

  • 0
    @ 2024-12-24 13:17:33

    模拟(nn)

    使用哈希表统计每个数出现的次数

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        cin>>n;
        map<int,int> h;
        for(int i=1;i<=n;i++)
        {
            int x;
            cin>>x;
            h[x]++; //x出现的次数增加
        }
        for(auto it:h) //遍历整个哈希表
        {
            cout<<it.first<<" "<<it.second<<endl;
        }
        return 0;
    }
    
    • 1

    Information

    ID
    454
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    # Submissions
    1
    Accepted
    1
    Uploaded By