Let the Balloon Rise

问题陈述:

  杭州电子科技大学HANGZHOU DIANZI UNIVERSITY Online Judge Problem - 1004

 

问题解析:

  输出每组数据中出现次数最多的颜色。

 

代码详解:  

 1 #include <iostream>

 2 #include <cstdio>

 3 #include <cstring>

 4 

 5 using namespace std;

 6 

 7 int main()

 8 {

 9     int i, j, n, max, count[1000];

10     char balloon[1000][16];

11     while(cin >> n && n!=0) {

12         for(i=0; i<n; i++) {

13             cin >> balloon[i];

14         }

15         for(i=0, max=0; i<n; i++) {

16             count[i] = 0;

17             for(j=i+1; j<n; j++) {

18                 if(strcmp(balloon[i], balloon[j]) == 0) {

19                     count[i]++;

20                 }

21                 max = max > count[i] ? max : count[i];

22             }

23         }

24         for(i=0; i<n; i++) {

25             if(count[i] == max) {

26                 cout << balloon[i] <<endl;

27                 break;

28             }

29         }

30         memset(balloon, 0, sizeof(balloon));

31         memset(count, 0, sizeof(count));

32     }

33     return 0;

34 }

 

转载请注明出处:http://www.cnblogs.com/michaelwong/p/4280665.html

  

你可能感兴趣的:(OO)