HDU 1004 Let the Balloon Rise

题目链接:HDU 1004

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

题意

吹气球(2333),输入很多不同颜色的气球,最后问什么颜色的气球最多,输出颜色

题解:

说实话,这道题我可能是走了很弯的路了,用了map来做,但是最后却没有用到map的优势,就当是练手速了,最后也是Wa了好几发才过。

建立气球类,表示这种气球的颜色,和当前数目,最后遍历一遍,更新最大数目的颜色,然后输出。

代码

#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;

typedef long long ll;

const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 5;
struct Boll {
    string color;
    int ID;
    int Num = 0;
};
Boll B[2000];
int main() {
    int n;
    while (cin >> n, n) {
        //memset(B, 0, sizeof B);
        for (int i(1); i <= 2000; i++)
            B[i].Num = 0;
        map<string, int>P;
        string t;
        int M = 1;
        for (int i(0); i < n; i++) {
            cin >> t;

            if (!P[t]) {
                P[t] = M;
                B[M].color = t;
                B[M].ID = M;
                B[M].Num++;
                M++;
            }
            else {
                B[P[t]].Num++;
            }
        }
        string ans;
        long long MIN = -INF;
        for (int i(1); i <= n; i++) {
            if (MIN<B[i].Num) {
                MIN = B[i].Num;
                ans = B[i].color;
            }
        }
        cout << ans << endl;
    }

    return 0;
}
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 一张图晒出你司的标语 #
4341次浏览 75人参与
# AI面会问哪些问题? #
28026次浏览 559人参与
# 开放七大实习专项,百度暑期实习值得冲吗 #
15273次浏览 221人参与
# 你的实习产出是真实的还是包装的? #
20248次浏览 342人参与
# 找AI工作可以去哪些公司? #
9210次浏览 239人参与
# 春招至今,你的战绩如何? #
65577次浏览 583人参与
# 厦门银行科技岗值不值得投 #
8053次浏览 188人参与
# 从事AI岗需要掌握哪些技术栈? #
9043次浏览 311人参与
# 中国电信笔试 #
32021次浏览 292人参与
# 你做过最难的笔试是哪家公司 #
33775次浏览 238人参与
# 投递几十家公司,到现在0offer,大家都一样吗 #
340878次浏览 2175人参与
# 哪些公司真双非友好? #
69630次浏览 289人参与
# 阿里笔试 #
178680次浏览 1317人参与
# 机械人避雷的岗位/公司 #
62704次浏览 393人参与
# 小马智行求职进展汇总 #
25133次浏览 80人参与
# 第一份工作一定要去大厂吗 #
14734次浏览 122人参与
# 金三银四,你的春招进行到哪个阶段了? #
22098次浏览 280人参与
# 为了减少AI幻觉,你注入过哪些设定? #
26263次浏览 310人参与
# 应届生第一份工资要多少合适 #
20691次浏览 86人参与
# 沪漂/北漂你觉得哪个更苦? #
9939次浏览 193人参与
# 聊聊你的职场新体验 #
336515次浏览 1895人参与
# HR最不可信的一句话是__ #
6306次浏览 114人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务