hdoj1004解题报告

题意:输入各种颜色的气球,输出气球数量最多的气球的颜色

#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    int n;
    char ball[1001][40];
    while (true)
    {
        cin >> n;
        if (n == 0)break;
        int count[1001] = {0};
        for (int i = 0; i < n; i++)
        {
            cin >> ball[i];
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = i; j < n; j++)
            {
                if(!strcmp(ball[i], ball[j]))
                {
                    count[i]++;
                }
            }
        }
        int max = 0;
        int pos;
        for (int i = 0; i < n; i++)
        {
            if (count[i] > max)
            {
                max = count[i];
                pos = i;
            }
        }
            cout << ball[pos] << endl;
    }

    return 0;
}


posted on 2013-12-22 13:17  冰迹风痕  阅读(98)  评论(0)    收藏  举报

导航