1 条题解

  • 0
    @ 2023-3-13 11:51:14

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    map<int,int> mp;
    int main(int argc, char** argv) {
    	ios::sync_with_stdio(false);
    	int n,x,maxn=-1;
    	cin>>n;
    	for(int i=1;i<=n;i++)
    	{
    		cin>>x;
    		mp[x]++;
    	}
    	
    	map<int,int>::iterator it;
    	for(it=mp.begin();it!=mp.end();it++)
    	   cout<<it->first<<" "<<it->second<<endl;
    	return 0;
    }
    
    

    Python :

    import math
    import sys
    n=int(input())
    s=list()
    for i in range(n):
        s.append(int(input()))
    d=dict()
    for item in s:
        if item not in d:
            d[item]=1
        else:
            d[item]=d[item]+1
    lst = sorted(d.items(),key=lambda x :x[0])
    for item in lst:
        print(item[0],item[1])
    
    
    • 1

    信息

    ID
    1820
    时间
    1000ms
    内存
    16MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者