zoukankan      html  css  js  c++  java
  • HDU 1004

    HDU 1004题目

    输入:

    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.

    输出:

    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.

    分析:本题使用了STL的map容器,写代码时在找出出现频率最高的字符时卡住了,其实需要两个变量,一个变量Max存储最高频率数,第二个变量MaxColor存储最高频率对应的字符。

    #include <iostream>
    #include <string>
    #include <map>
    using namespace std;
    map<string ,int> cnt;//
    map<string ,int> :: iterator iter;
    
    int main(){
      int N;
      string s;
    
      while(cin>>N&&N){
        int Max=0;
        string MaxColor;
        cnt.clear();
        while(N--){
        cin>>s;
        if(!cnt.count(s)) cnt[s]=0;
        cnt[s]++;
        }
        for(iter=cnt.begin();iter!=cnt.end();iter++)
        {
            if(iter->second > Max) {Max = iter->second;MaxColor = iter->first;}
        }
        cout<<MaxColor<<endl;
      }
        return 0;
    }
    技进乎艺,艺进乎道
  • 相关阅读:
    Djiango项目的创建以及配置介绍1
    最大矩形土地 单调栈或者DP
    0917 lxs 反思
    0915 反思
    codeforces 1209/C Paint the Digits 观察
    NOIP2014 解方程 秦九韶算法+多项式处理
    整数拆分问题
    机器人M号
    有趣的数列 唯一分解定理+卡特兰数
    数位DP 不要62
  • 原文地址:https://www.cnblogs.com/weekend/p/5464450.html
Copyright © 2011-2022 走看看