hdu 1004 颜色与数字(map水题)

Sample Input
5 //T
green
red
blue
red
red 统计颜色的次数 输出最多的颜色
3
pink
orange
pink
0

Sample Output
red
pink

 

 1 # include <iostream>
 2 # include <cstdio>
 3 # include <cstring>
 4 # include <string>
 5 # include <map>
 6 using namespace std ;
 7 
 8 int main ()
 9 {
10 //    freopen("in.txt","r",stdin) ;
11     int T ;
12     map<string,int> m ;
13     while(scanf("%d" , &T) , T)
14     {
15         m.clear() ;
16         string name ;
17         string maxname ;
18         while(T--)
19        {
20           cin>>name ;
21           m[name]++ ;
22        }
23        int max = 0 ;
24        map<string,int>::iterator p ;
25        for (p = m.begin() ; p != m.end() ; p++)
26        {
27              if (p->second > max)
28              {
29                   max = p->second ;
30                   maxname = p->first ;
31              }
32        }
33        cout << maxname<<endl ;
34         
35     }
36     
37     
38     
39     return 0 ;
40 }
View Code

 

posted @ 2015-05-12 17:08  __Meng  阅读(205)  评论(0编辑  收藏  举报