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 ...
随机推荐
- Kaldi的delta特征
Delta特征是将mfcc特征(13维)经过差分得到的 它是做了一阶二阶的差分 提取的mfcc特征是13维的 然后通过delta就变成了39维 一阶差分: D(P(t))=P(t)-P(t-1) 二阶 ...
- python的sys.args使用
一.sys 模块 sys是Python的一个「标准库」,也就是官方出的「模块」,是「System」的简写,封装了一些系统的信息和接口. 官方的文档参考:https://docs.python.org/ ...
- Python之 string 和 random方法
1. import string import string print(string.ascii_lowercase) #输出全部小写字母a-z print(string.ascii_letters ...
- Leetcode#118. Pascal's Triangle(杨辉三角)
题目描述 给定一个非负整数 numRows,生成杨辉三角的前 numRows 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例: 输入: 5 输出: [ [1], [1,1], [1,2, ...
- Shiro入门 - 通过自定义Realm连数数据库进行授权
shiro-realm.ini [main] #自定义Realm myRealm=test.shiro.MyRealm #将myRealm设置到securityManager,相当于Spring中的注 ...
- Django学习手册 - ORM 多对多表
定义表结构: class Host(models.Model): hostname = models.CharField(max_length=32) port = models.IntegerFie ...
- springboot中.yml没有spring的小叶子标志解决办法
我的idea springboot项目中有两个.yml文件,一个application.yml,一个log4j2.yml,但是只有application.yml显示的是树叶图标,如下所示 做如下配置后 ...
- python,栈的小例子
''' 1.首先确认栈的概念,先进后出 2.初始化的时候如果给了一个数组那么就要将数组进栈 ''' class Stack: def __init__(self,start=[]): self.sta ...
- Linux下查询文件的md5,sha1值
验证下载下来的文件包是不是一致 ··· 验证md5值 #md5sum filename 验证shal值 #sha1sum filename ···
- Nand flash 三种类型SLC,MLC,TLC【转】
转自:https://blog.csdn.net/fc34235/article/details/79584758 转载自:http://diy.pconline.com.cn/750/7501340 ...