zoukankan      html  css  js  c++  java
  • HDU-1004 Let the Balloon Rise (STL map)

    一时水题一时爽,一直水题一直爽(比赛全是打铁场)

    题意:

    有n个例子,统计颜色出现个数。自然联想到map来映射统计(顺便就当写下map用法)

    #include <map>
    映射关系map<key,value> 利用key来映射到value上
    map iterator迭代器,指向一个“键值对”,first代表"Key", second代表"value“. 例如iterator it = map<a,b>tmp ,it->first,it->second
    思考map<string ,int>word 与 map<int ,map>word区别(构造)

    完整代码:注意一下C++提交可能不能通过要G++才行

    #include<cstdio>
    #include<iostream>
    #include<map>//引入map容器
    using namespace std;
    int main()
    {
        int n,num;
        string s,ans;
        while(cin>>n&&n)
        {
            num=-10;//num来记录最大值(取一个较小的数最为min)
            map<string ,int >word;//声明一个关键字为字符串值为数字的map
            map<string ,int>::iterator it;//迭代器 
            while(n--)
            {
                cin>>s;
                word[s]++;//关键字的值加一
            }
            for(it=word.begin();it!=word.end();it++)
            {
                if(it->second>num)
                {
                    num=it->second;
                    ans=it->first;
                }
            }
            cout<<ans<<endl;
        }
    }
  • 相关阅读:
    企业生产环境不同业务linux系统分区方案
    linux 文件 s 权限
    shell中的命令与特殊符号
    Linux数组基础
    shell脚本学习(1)
    文件的压缩与打包
    Linux 磁盘管理基础命令df,du,fdisk,mke2fs
    mkpasswd的使用
    P1080 国王游戏
    P1315 观光公交
  • 原文地址:https://www.cnblogs.com/Tianwell/p/11195479.html
Copyright © 2011-2022 走看看