HDU-1004—Let the Balloon Rise

简介: HDU-1004—Let the Balloon Rise



Let the Balloon Rise

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 90389    Accepted Submission(s): 34336


Problem 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

 


Author

WU, Jiazhi

 


Source

ZJCPC2004

 


Recommend

JGShining   |   We have carefully selected several similar problems for you:  1005 1009 1019 1021 1012

 


题目分析:

题目意思已经很明白了,就是输出出现次数最多的单词

第一种写法  map

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
using namespace std;
int main()
{
  int n;
  while(cin>>n,n)
  {
    string a;
    map<string,int>st;// 定义map容器类型
    while(n--)
    {
      cin>>a;
      st[a]++;//这里如果 a  出现一次就加1  记录每个单词的次数     首先要明白  map  容器存储是不重复的
    }
    int max=0;
    map<string,int>::iterator it;   //  定义map  指针    就相当于  int类型的   int i; 的定义
    for(it=st.begin();it!=st.end();it++)
    {
      if((*it).second>max)
          max=(*it).second;
    }  //  这里就是遍历一下出现次数最多是多少
    for(it=st.begin();it!=st.end();it++)
    {
        if((*it).second==max)  //  这里就是查  次数最多单词的位置    (*it).second   也可以写成  it->second
        cout<<(*it).first<<endl;
    }
  }
  return 0;
}



第二种简单模拟

#include<stdio.h>
#include<string.h>
int main()
{
    char a[1005][20];
    int i,j,n;
    int b[1005];
    while(scanf("%d",&n)&&(n!=0))
    {
        memset(b,0,sizeof(b));
        for(i=0; i<n; i++)
        {
            scanf("%s",a[i]);
        }
        for(i=0; i<n; i++)
            for(j=0; j<n; j++)
            {
                if(strcmp(a[i],a[j])==0)
                    b[i]++;
            }
        int max=-1;
        int k;
        for(i=0; i<n; i++)
        {
            if(max<b[i])
            {
                max=b[i];
                k=i;
            }
        }//找出出现颜色最多的下标
        printf("%s\n",a[k]);
    }
    return 0;
}




















目录
相关文章
|
5月前
|
传感器 自动驾驶 机器人
PTP 时钟:精准时钟同步的核心力量​
西安同步电子科技推出的SYN2407系列PTP时钟模块,包含多种型号,支持纳秒级时间同步精度,适用于工业自动化、汽车电子及电信等领域。该系列模块具备主从时钟切换功能,支持IEEE1588、IEEE802.1AS等协议,适应复杂网络环境。通过高精度时钟同步,助力生产线高效运行、汽车电子系统精准配合及电信网络稳定传输,推动各行业迈向更高效、精准的数字化未来。
|
大数据 分布式计算 流计算
阿里巴巴高级技术专家章剑锋:大数据发展的 8 个要点
笔者从 2008 年开始工作到现在也有 11 个年头了,一路走来都在和数据打交道,做过大数据底层框架内核的开发(Hadoop,Pig,Tez,Spark,Livy),也做过上层大数据应用开发(写 MapReduce Job 做 ETL ,用 Hive 做 Ad hocquery,用 Tableau 做数据可视化,用 R 做数据分析)。
6771 57
|
Android开发
eclipse修改文件编码,window系统
Eclipse中经常会遇到中文乱码的问题,一般都是编码格式不一致,eclipse默认的编码格式是GBK,这里推荐统一使用UTF-8。
|
分布式计算 Spark
【Spark】【RDD】从本地文件系统创建RDD
【Spark】【RDD】从本地文件系统创建RDD
195 0
【Spark】【RDD】从本地文件系统创建RDD
|
消息中间件 设计模式 Kafka
消息队列使用场景
说到消息中间件,我使用比较多的就是RabbitMQ。在分布式系统中,不同模块之间的通信,除了可以使用 RPC方式进行调用外,MQ也是另外一种方式,也是进程之间进行通信的一种方法。 消息队列:传递消息的队列。参与传递消息的双方称为生产者、消费者。生产者和消费者可以只有一个实例,也可以集群部署。
239 0
|
域名解析 网络协议 Linux
Centos 7 使用 vsftpd 搭建 FTP 服务器
本文主要为大家介绍 Centos 7 环境下使用 vsftpd 搭建 FTP 服务器的过程。
1161 0
Centos 7 使用 vsftpd 搭建 FTP 服务器
|
SQL 人工智能 算法
阿里这套算法,让1亿只猫惊呆了
小叽导读:天猫精灵CC/CCL是这样一款智能音箱:2019中国的宠物猫狗综合超过1亿,,天猫精灵能够识别你家的萌宠,并把他们最精彩瞬间截取下来推荐给你!AI Labs研发了创新的智能摄影算法服务宠《萌大机密》,以家中宠物做为主要目标,把真正的智能相机带进中国千万用户的家庭之中。让你不在家,也能陪伴萌宠。
6184 0
阿里这套算法,让1亿只猫惊呆了
|
3天前
|
存储 关系型数据库 分布式数据库
PostgreSQL 18 发布,快来 PolarDB 尝鲜!
PostgreSQL 18 发布,PolarDB for PostgreSQL 全面兼容。新版本支持异步I/O、UUIDv7、虚拟生成列、逻辑复制增强及OAuth认证,显著提升性能与安全。PolarDB-PG 18 支持存算分离架构,融合海量弹性存储与极致计算性能,搭配丰富插件生态,为企业提供高效、稳定、灵活的云数据库解决方案,助力企业数字化转型如虎添翼!