杭电1004
/* 统计出现颜色最多的气球并输出颜色,在题目中并没有给出颜色有多少种,所以可以考虑用vector来做,但是开个数组1000也是可以过的 */ #include <iostream> #include <string> using namespace std; int main() { int n, i, j; string color[1001], col; int count[1001]; while (cin>>n) { if (n == 0) break; for (i = 0; i < n; i++) { color[i] = ""; count[i] = 0; } for (i = 0; i < n; i++) { cin>>col; for (j = 0; j < n; j++) { if (color[j] == col) { count[j]++; break; } } if (j == n) { for (j = 0; j < n; j++) { if(color[j] == "") { color[j] = col; count[j]++; break; } } } } int max = count[0]; int index = 0; for (i = 0 ; i < n; i++) { if (max < count[i]) { max = count[i]; index = i; } } cout<<color[index]<<endl; } return 0; }