码迷,mamicode.com
首页 > 其他好文 > 详细

SDNU 1125.Let the Balloon Rise

时间:2019-06-05 21:28:42      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:min   cst   his   time   end   type   proc   using   single   

Description

Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges‘ favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.
This year, they decide to leave this lovely job to you.

Input

Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.
A test case with N = 0 terminates the input and this test case is not to be processed.

Output

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.

Sample Input

5
green
red
blue
red
red
3
pink
orange
pink
0

Sample Output

red
pink

Source

思路:这道题,一开始我想了很多,比如用map把string和int存起来,然后用vector把map里的内容存起来再排序。后来事实证明是我想多了,完全可以用map的迭代器把map里的东西存入结构体,再排个序,输出就完事儿~
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;
#define ll long long

map<string, int>mp;

struct node
{
    string s;
    int num;
} r[1000+8];

int n;
string si;

bool cmp(node a, node b)
{
    return a.num>b.num;
}

int main()
{
    while(~scanf("%d", &n) && n != 0)
    {
        mp.clear();
        for(int i = 0; i<n; i++)
        {
            cin>>si;
            if(mp[si])mp[si]++;
            else mp[si] = 1;        }
        int id = 0;
        for(map<string, int>::iterator ii = mp.begin(); ii != mp.end(); ii++)
        {
            r[id].s = ii->first;
            r[id].num = ii->second;
            id++;
        }
        sort(r, r+id, cmp);
        cout<<r[0].s<<endl;
    }
    return 0;
}

 

SDNU 1125.Let the Balloon Rise

标签:min   cst   his   time   end   type   proc   using   single   

原文地址:https://www.cnblogs.com/RootVount/p/10981994.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!