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.

InputInput 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. 
OutputFor 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
常规解法:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
char str[10000][20],k[100];
int n;
while (cin >> n && n != 0)
{
int a[10000] = { 0 };
int mark = 0;
int max = 0,ko = 0;
for (int i = 0; i < n; i++)
{
int flag = 0;
cin >> k;
for (int j = 0; j < mark; j++)
{
if (strcmp(str[j], k)==0)
{
a[j]++; flag = 1;
if (a[j] > max)
{
max = a[j];
ko = j;
}
break;
}
}
if (!flag)
strcpy(str[mark++], k);
}
cout << str[ko] << endl;
}
return 0;
}

  map的解法(水题):

 #include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
int ballnum;
while (cin >> ballnum && ballnum != )
{
string temp,ko;
int bigger = ;
map<string, int> balloon; for (int i = ; i<ballnum; i++)
{
cin >> temp;
balloon[temp]++;
if (balloon[temp] > bigger)
{
bigger = balloon[temp];
ko = temp;
}
}
cout << ko << endl; }
return ;
}

Let the Balloon Rise <map>的应用的更多相关文章

  1. HDU 1004 Let the Balloon Rise map

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  2. Let the Balloon Rise(map)

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  3. HDU 1004 Let the Balloon Rise(map应用)

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  4. Let the Balloon Rise map一个数组

    Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the ...

  5. hdoj-1004-Let the Balloon Rise(map排序)

    map按照value排序 #include <iostream> #include <algorithm> #include <cstring> #include ...

  6. HDU1004 Let the Balloon Rise(map的简单用法)

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

  7. HDU 1004 Let the Balloon Rise【STL<map>】

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  8. hdu 1004 Let the Balloon Rise strcmp、map、trie树

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  9. HDU 1004 Let the Balloon Rise(map的使用)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1004 Let the Balloon Rise Time Limit: 2000/1000 MS (J ...

随机推荐

  1. python 关于文件操作

    ,要求在文件 .py 第六行插入一句话: #cat /root/python/2.py 2 昨夜雨疏风骤1 3 昨夜雨疏风骤2 4 昨夜雨疏风骤3 5 昨夜雨疏风骤4 6 昨夜雨疏风骤5 7 昨夜雨疏 ...

  2. Spark的四种部署方式并对应四种提交方式

    1 Local模式     本地模式  local模式 一台机器即可,开箱即用 不指定master,或者 --master  local  local[N]  local[*] local模式下,使用 ...

  3. window.name

    name 设置或返回存放窗口的名称的字符串.该名称是在 open()方法创建窗口时指定的或者使用一个<frame>标记的name属性指定的. 窗口的名称可用作一个<a>或者&l ...

  4. It's a Mod, Mod, Mod, Mod World Kattis - itsamodmodmodmodworld (等差数列求和取模)

    题目链接: D - It's a Mod, Mod, Mod, Mod World Kattis - itsamodmodmodmodworld 具体的每个参数的代表什么直接看题面就好了. AC代码: ...

  5. Spring的jdbcTemplate操作-未完整

    1 spring框架一站式框架(1)针对javaee三层,每一层都有解决技术(2)在dao层,使用 jdbcTemplate 2 spring对不同的持久化层技术都进行封装

  6. python,小练习(计算两点之间直线长度)

    #首先引入数学函数 import math #创建一个点的类 class Point(): #初始化点的坐标(x,y) def __init__(self,x=0,y=0): self.x = x s ...

  7. Linker Scripts3--链接脚本概述

    1.前言 本文主要翻译了The Link Script英文文献. (1)每个链接都是由链接脚本控制,链接脚本是用链接命令语言写的: (2)链接脚本的主要目的是描述输入文件的sections如何映射到输 ...

  8. Vue.js 子组件的异步加载及其生命周期控制

    前端开发社区的繁荣,造就了很多优秀的基于 MVVM 设计模式的框架,而组件化开发思想也越来越深入人心.这其中不得不提到 Vue.js 这个专注于 VM 层的框架. 本文主要对 Vue.js 组件化开发 ...

  9. expect学习笔记及实例详解

    因为最近正在学习expect脚本,但是发现网上好多文章都是转载的,觉得这篇文章还不错,所以简单修改之后拿过来和大家分享一下~ 1. expect是基于tcl演变而来的,所以很多语法和tcl类似,基本的 ...

  10. $Django cbv源码分析 djangorestframework框架之APIView源码分析

    1 CBV的源码分析 #视图 class login (View): pass #路由 url(r'^books/$', views.login.as_view()) #阅读源码: #左侧工程栏--- ...