4 条题解

  • 2
    @ 2023-10-8 21:43:41

    我这可能是最简代码了吧

    #include<bits/stdc++.h>
    using namespace std;
    int a[200020];
    int main(){
    	int n;cin>>n;
    	for(int i=0;i<n;i++){
    		cin>>a[i];
    	}
    	sort(a,a+n);
    	int c=1;
    	for(int i=0;i<n;i++){
    		if(a[i]==a[i+1]){
    			c++;
    		}else{
    			cout<<a[i]<<" "<<c<<endl;
    			c=1;
    		}
    	}
    	return 0;
    }
    
    • 1
      @ 2024-2-5 8:31:45

      考察mapmap的基础用法

      核心代码:

      for (int i = 1; i <= n; i++)
      {
          cin >> x;
          mp[x]++;
      }
      for (auto b : mp)
          cout << b.first << " " << b.second << endl;
      
      • 1
        @ 2022-12-13 14:02:52
        #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;
        }
        
        • 0
          @ 2024-2-17 17:16:38
          #include <bits/stdc++.h>
          using namespace std;
          int n,x;
          map<int,long long>m;
          map<int,long long>::iterator it;
          int main(){
              cin>>n;
              for (int i=1;i<=n;i++){
                  cin>>x;
                  m[x]++;
              }
              for (it=m.begin();it!=m.end();it++)cout<<it->first<<" "<<it->second<<endl;
              return 0;
          }
          
          • 1

          [普及][NOIP2007 提高组] 统计数字

          信息

          ID
          1612
          时间
          1000ms
          内存
          256MiB
          难度
          6
          标签
          递交数
          171
          已通过
          53
          上传者