Let the Balloon Rise <map>的应用
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>的应用的更多相关文章
- 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 ...
- Let the Balloon Rise(map)
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU 1004 Let the Balloon Rise(map应用)
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- Let the Balloon Rise map一个数组
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the ...
- hdoj-1004-Let the Balloon Rise(map排序)
map按照value排序 #include <iostream> #include <algorithm> #include <cstring> #include ...
- HDU1004 Let the Balloon Rise(map的简单用法)
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 洛谷P2699小浩的幂次运算
二分走一波,没想到题解的大佬做法 p_q 注意爆long long,所以先对数取一下上限 二分确定下限,然后输出 #include<stdio.h> #include<math.h& ...
- python 函数名 、闭包 装饰器 day13
1,函数名的使用. 函数名是函数的名字,本质就是变量,特殊的变量.函数名()加括号就是执行此函数. 1,单独打印函数名就是此函数的内存地址. def func1(): print(555) print ...
- Vuejs---《Vue.js + Node.js-构建音乐播放器新玩法-video》
官方文档:http://vuejs.org/v2/guide/syntax.html 中文文档: https://cn.vuejs.org/v2/guide/syntax.html https://g ...
- java json 转换
1.直接输出: 2.字符串 通过eval转换输出,里面涉及到一个转义问题,还要注意eval的用法里面需要加"("+ + ")" 3.
- php-mysql问题:mysqli_connect(): Headers and client library minor version mismatch. Headers:50556 Library:50637
问题现象 mysqli_connect(): Headers and client library minor version mismatch. Headers:50556 Library:5063 ...
- requirements.txt文件教程
方法有2种,命令都是一样,只是执行地方不一样 此方法主要用于迁移新环境使用,为防止代码出现问题,最好使用原装库,所以就有了迁移代码和库的操作 第一种:在pycharm中,左下角有个双重正方形,点击里面 ...
- SpringTask定时任务的使用
实现定时任务简单的有四种方式:Timer\ScheduledThreadPool线程池\quartz(常用),还有另一种就是springtask. 都说springtask上手简单,于是简单的研究一下 ...
- 【转】python包导入细节
[转]python包导入细节 包导入格式 导入模块时除了使用模块名进行导入,还可以使用目录名进行导入.例如,在sys.path路径下,有一个dir1/dir2/mod.py模块,那么在任意位置处都可以 ...
- ethtool 解决网卡丢包严重和网卡原理【转】
转自:https://blog.csdn.net/u011857683/article/details/83758869 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog ...
- lzstring
import lzstring ic = {"name": "root", "password": "123456"} ...