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;
    }
    
  • 相关阅读:
    SQL Analytic Functions 分析函数
    SQL Cumulative Sum累积求和
    Data import/export of Netezza using external table
    重复数据分析的三个常用语法distinct, group by, partition by
    数据库开发常备技能
    Versioned table in Netezza
    主元素判断
    数据结构考研模糊知识点2.1
    数据结构考研模糊知识点1.2
    数据结构考研模糊知识点1.1
  • 原文地址:https://www.cnblogs.com/Titordong/p/9601900.html
Copyright © 2011-2022 走看看