5 条题解

  • 1
    @ 2022-3-20 20:51:58
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <iostream>
    using namespace std;
    int a [1000];
    int main()
    {
    	int n ;
    	cin >> n;
    	int maxx = 0;
    	for(int i = 0,x ;i < n ;i++)
    	{
    		cin >> x;
    		a[x]++;
    		maxx = max(maxx , a[x]);
    	}
    	for(int i = 1 ; i <= 100 ; i++)
    	{
    		if(a[i] == maxx)
    		{
    			cout << i << " " << a[i] << endl;
    		}
    	}
    }
    
    • 0

      #include<bits/stdc++.h> using namespace std; int a [1000]; int main(){ int n ; cin >> n; int maxx = 0; for(int i = 0,x ;i < n ;i++) { cin >> x; a[x]++; maxx = max(maxx , a[x]); } for(int i = 1 ; i <= 100 ; i++) { if(a[i] == maxx) { cout << i << " " << a[i] << endl; } } return 0; }

      • 0
        @ 2024-4-27 15:40:26
        #include<bits/stdc++.h> 
        using namespace std;
        const int N = 1e6+ 10;
        const int INF = 0x3f3f3f3f;
        int n,a[N],x,maxx=-1;
        int main(){
            cin>>n;
            for(int i=1;i<=n;i++){
                cin>>x;
                a[x]++;
                if(a[x]>maxx)
        	        maxx=a[x];
        }
            for(int i=1;i<=100;i++){    
                if(a[i]==maxx)
                    cout<<i<<" "<<a[i]<<endl;
               }
        }
        
        • 0
          @ 2024-3-19 17:38:30
          #include <iostream>
          using namespace std;
          int a [1145];
          int main()
          {
          	int n ;
          	cin >> n;
          	int maxx = 0;
          	for(int i = 0,x ;i < n ;i++)
          	{
          		cin >> x;
          		a[x]++;
          		maxx = max(maxx , a[x]);
          	}
          	for(int i = 1 ; i <= 100 ; i++)
          	{
          		if(a[i] == maxx)
          		{
          			cout << i << " " << a[i] << endl;
          		}
          	}
          }
          
          
          • 0
            @ 2023-2-2 12:04:38

            提示真良心

            按着提示做就行了

            方法二更容易

            方法一:

            #include <iostream>
            #include <stack>
            #include <cmath>
            #include <vector>
            #include <string.h>
            #include <queue>
            #include <stdio.h>
            #include <iomanip>
            #include <cstdio>
            #include <algorithm>
            #define int long long
            using namespace std;
            const int N = 1e4+ 10;
            const int INF = 0x3f3f3f3f;
            int a[N], maxx[N]/*出现次数*/;
            signed main()
            {
            	int n;
                cin >> n;
                for(int i = 1; i <= n; i++)
                {
                    cin >> a[i];
                }
                sort(a + 1, a + n + 1);
                int k = a[1], cnt = 1, maxn = -INF;
                for(int i = 2; i <= n + 1; i++)
                {
                    if(k == a[i])//当前的与上一个相等
                    {
                        cnt++;
                    }
                    else
                    {
                        maxx[a[i - 1]] = cnt;//上一个数赋值
                        maxn = max(maxn, cnt);//出现最大次数
                        k = a[i];//当前值
                        /*
                        //cnt = 0;
                        if(k == a[i])
                        {
                            cnt++;
                        }
                        */
                        cnt = 1;//不要设为0,理由见上注释代码
                    }
                }
                for(int i = 1; i <= 100; i++)
                {
                    if(maxx[i] == maxn)
                    {
                        cout << i << " " << maxn << endl;
                    }
                }
            	return 0;
            }
            

            方法二:

            不用注释应该也能看懂

            #include <iostream>
            #include <stack>
            #include <cmath>
            #include <vector>
            #include <string.h>
            #include <queue>
            #include <stdio.h>
            #include <iomanip>
            #include <cstdio>
            #include <algorithm>
            #define int long long
            using namespace std;
            const int N = 1e2 + 10;
            const int INF = 0x3f3f3f3f;
            int a[N];
            signed main()
            {
            	int n, maxx = -INF;
                cin >> n;
                for(int i = 1; i <= n; i++)
                {
                    int x;
                    cin >> x;
                    a[x]++;
                    maxx = max(maxx, a[x]);
                }
                for(int i= 1; i <= 100; i++)
                {
                    if(a[i] == maxx)
                    {
                        cout << i << " " << maxx << endl;
                    }
                }
            	return 0;
            }
            
            • 1

            信息

            ID
            998
            时间
            1000ms
            内存
            128MiB
            难度
            4
            标签
            递交数
            354
            已通过
            172
            上传者