This year, they decide to leave this lovely job to you.
A test case with N = 0 terminates the input and this test case is not to be processed.
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
附上AC代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
const double PI = 3.14159265;
const double E = 2.71828182846;
struct node
{
int cnt;
int flag;
};
bool cmp(node a, node b);
int main()
{
ios::sync_with_stdio(false);
int n;
while (cin >> n && n != 0)
{
string str[1000];
node rank[1000];
for (int i=0; i<n; i++)
{
cin >> str[i];
rank[i].cnt = rank[i].flag = 0;
}
sort(str, str+n);
int count = 0;
rank[0].cnt = 1;
rank[0].flag = 0;
for (int i=1; i<n; i++)
{
if (str[i] != str[i-1])
{
rank[++count].cnt = 1;
rank[count].flag = i;
}
else
rank[count].cnt++;
}
sort(rank, rank+count+1, cmp);
cout << str[rank[count].flag] << endl;
}
return 0;
}
bool cmp(node a, node b)
{
return a.cnt < b.cnt;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/silenceneo/article/details/47747543