2 solutions

  • 1
    @ 2022-1-5 22:01:57

    很简单,随便看看吧

    #include <bits/stdc++.h>
    using namespace std;
    map<string,int>ma;
    string ss;
    int main(){
    	int n,maxx=-100;
    	cin>>n;
    	while(n--){
    		string s;
    		cin>>s;
    		ma[s]++;
    		if(ma[s]>maxx) ss=s,maxx=ma[s];
    	}
    	cout<<ss;
    	return 0;
    }
    
    • 0
      @ 2022-1-13 13:15:14

      ##两个map,应该还是很好理解,就是映射之间的关系

      #include<bits/stdc++.h>
      using namespace std;
      typedef long long ll;
      const int N = 1e6+5;
      int main()
      {
      	map<string,int> q;
      	map<int,string> max1; 
      	int n,_max=0;
      	cin>>n;
      	for(int i=0;i<n;i++)
      	{
      		string s;
      		cin>>s;
      		q[s]++;
      		if(q[s]>_max) {
      			_max=q[s];
      			max1[_max]=s;
      		}
      	}
      	cout<<max1[_max]<<endl;
      	return 0;
      }
      
      • 1

      Information

      ID
      1096
      Time
      1000ms
      Memory
      16MiB
      Difficulty
      2
      Tags
      # Submissions
      45
      Accepted
      30
      Uploaded By