zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    python笔记-列表和元组
    T-sql for xml path使用(转)
    除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效。
    VS2015 经常不出现智能提示,代码颜色也没有了
    虚拟机重新决定网卡地址时,老是报错
    模块的命令
    关闭NetworkManager的作用
    centos6上yum安装drbd(内核:2.6.32.696)
    检查硬件变化的命令kudzu
    parted分区和挂载及非交互式操作
  • 原文地址:https://www.cnblogs.com/Titordong/p/9601900.html
Copyright © 2011-2022 走看看