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 }

 

posted on 2012-11-19 13:40 symons 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/symons1992/archive/2012/11/19/2777129.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值