hlg_1109_stl应用

之前看没头绪,现在看太水了。水过。

 1 #include <iostream>
 2 #include <map>
 3 #include <string>
 4 using namespace std;
 5 bool judge(string a,string b)
 6 {
 7     if(a<b) return 0;
 8     else return 1;
 9 }
10 int main()
11 {
12     map<string,int>haha;
13     map<string,int>::iterator it;
14     string abc,tt,maxsign;
15     int i,n,t,j,max;
16     while(cin>>t&&t)
17     {
18         getchar();
19         while(t--)
20         {
21             max=0;
22             haha.clear();
23             getline(cin,abc);
24             n=abc.length();
25             for(i=1;i<n;++i)
26             {
27                 tt="00";
28                 tt[0]=abc[i-1];
29                 tt[1]=abc[i];
30                 haha[tt]++;
31             }
32             for(it=haha.begin();it!=haha.end();++it)
33             {
34                 if(it->second>max)
35                 {
36                     maxsign=it->first;
37                     max=it->second;
38                 }
39                 else    if(it->second==max&&judge(it->first,maxsign)==0)//0代表it->first小于maxsign  1代表大于
40                 {
41                     maxsign=it->first;
42                     max=it->second;
43                 }
44             }
45             cout<<maxsign<<endl;
46         }
47         cout<<endl;
48     }
49     return 0;
50 }
原文地址:https://www.cnblogs.com/symons1992/p/2777129.html