zoukankan      html  css  js  c++  java
  • SDNU 1125.Let the Balloon Rise

    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;
    }
  • 相关阅读:
    spring data实现自定义的repository实现类,实现跟jpa联通
    SQLYog快捷键大全
    JSP 中EL表达式用法详解
    java中的标记接口
    单元测试中快速执行某个方法
    Spring Boot 以 jar 包方式运行在后台
    Spring Data JPA
    扩展spring data jpa的数据更新方法时注意事项
    在Spring Data JPA 中使用Update Query更新实体类
    高速创建和mysql表相应的java domain实体类
  • 原文地址:https://www.cnblogs.com/RootVount/p/10981994.html
Copyright © 2011-2022 走看看