博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU1004 Let the Balloon Rise
阅读量:7115 次
发布时间:2019-06-28

本文共 795 字,大约阅读时间需要 2 分钟。

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1004
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
    int  nCount=0; 
    string strTmp;
    while(cin>>nCount&&nCount!=0)
    {
        map<string,int> mapColor;//用map容器非常方便
        for(int i=0;i<nCount;++i)
        {
            cin>>strTmp;
            mapColor[strTmp]++;
        }
       map<string, int>::iterator iter;
       int max = -1;
       for(iter = mapColor.begin(); iter != mapColor.end(); iter++)
       {//第一次遍历标记最大次数所在位置
           if(iter->second>max)
           {
               max = iter->second;
           }
       }
       for(iter = mapColor.begin(); iter != mapColor.end(); iter++)
       {//第二次遍历找到标记的位置
           if(iter->second==max)
           {
               cout<<iter->first<<endl;
           }
       }  
    }
    return 0;
}
由于map只能对关键字进行排序,所以这里放弃考虑排序了,直接两次遍历map容器,算法复杂度O(n)
本文转自Phinecos(洞庭散人)博客园博客,原文链接http://www.cnblogs.com/phinecos/archive/2007/12/23/1011501.html,如需转载请自行联系原作者
你可能感兴趣的文章
php switch case语句用法
查看>>
docker探索-docker容器基本操作(五)
查看>>
spring boot 中logback多环境配置
查看>>
CTF---Web入门第十二题 程序逻辑问题
查看>>
当ThreadLocal碰上线程池
查看>>
子类构造方法
查看>>
关于Spring中的<context:annotation-config/>配置
查看>>
Java Exceptions
查看>>
[RK3288][Android6.0] 调试笔记 --- 系统识别不同硬件版本方法【转】
查看>>
jquery的onclick(this)方法
查看>>
Laravel之路(事务)mysql事务
查看>>
Aurora的安装和中文配置
查看>>
oracle数据库出现“批处理中出现错误: ORA-00001: 违反唯一约束条件”解决方法
查看>>
SpringMVC(十二):SpringMVC 处理输出模型数据之@ModelAttribute
查看>>
Java多线程:死锁
查看>>
【深度学习系列】CNN模型的可视化
查看>>
memory consistency
查看>>
CSS选择器的新用法
查看>>
PowerShell 并行执行任务
查看>>
C++中的const成员函数(函数声明后加const,或称常量成员函数)用法详解
查看>>