我是靠谱客的博主 欣慰荷花,最近开发中收集的这篇文章主要介绍map 键值对 用vector对值进行排序Let the Balloon Rise,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Let the Balloon Rise

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 146427    Accepted Submission(s): 58133


 

Problem 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

 

 

#include<iostream>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
map<string,int> a;
int cmp(const pair<string,int> &x,const pair<string,int> &y)
{
    return x.second>y.second;
}
void k(vector<pair<string,int> >&x,map<string,int> &y)
{
    for(map<string,int>::iterator it=y.begin();it!=y.end();it++)
    {
        x.push_back(make_pair(it->first,it->second));
    }
    sort(x.begin(),x.end(),cmp);
}
int main()
{
    int n,i,j,t;
    string s;
    
    while(~scanf("%d",&n),n)
    {
        for(i=0;i<n;i++)
        {
            cin>>s;
            if(a.count(s)==0)
            a.insert(make_pair(s,1));
            else
            a.find(s)->second+=1;
        }
        vector<pair<string,int> >b;
        k(b,a);
        cout<<b[0].first<<endl;
        
        a.clear();
    }
    return 0;
}

 

 

最后

以上就是欣慰荷花为你收集整理的map 键值对 用vector对值进行排序Let the Balloon Rise的全部内容,希望文章能够帮你解决map 键值对 用vector对值进行排序Let the Balloon Rise所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(36)

评论列表共有 0 条评论

立即
投稿
返回
顶部