2 条题解

  • 1
    @ 2023-9-25 18:14:35

    已AC,放心食用

    #include <iostream>
    #include <algorithm>
    using namespace std;
    int n, x, speech[105], cnt;
    int main()
    {
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            cin >> x;
            if (!speech[x]++)
            {
                cnt++;
            }
        }
        cout << cnt << endl;
        for (int i = 1; i <= 100; i++)
        {
            if (speech[i] != 0)
            {
                cout << i << " " << speech[i] << endl;
            }
        }
        return 0;
    }
    
    • 1
      @ 2023-1-21 19:54:58
      #include<bits/stdc++.h>
      using namespace std;
      int a[110];//用于a[1]~a[100]记录1~100出现的次数
      int n, t, c = 0; 
      int main()
      {
      	cin >> n;
      	for(int i = 1; i <= n; i++){
      		cin >> t;
      		//t,出现过的数字
      		a[t]++;
      		//如果t是第一次出现
      		if(a[t] == 1) c++; 
      	}
      	cout << c << endl;
      	for(int i = 1; i <= 100; i++){
      		if(a[i] > 0){
      			cout << i << ' ' << a[i] << endl;
      		}
      	}
      	return 0;
      }
      
      
      
      • 1

      信息

      ID
      722
      时间
      1000ms
      内存
      128MiB
      难度
      1
      标签
      递交数
      35
      已通过
      29
      上传者