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 ...
随机推荐
- Windows jdk安装以及版本切换
Windows jdk版本切换 一.安装 1.下载 官网: Java SE Development Kit 8 Downloads Java SE 7 Archive Downloads 1.7之前的 ...
- nmap 使用总结
nmap 网络探测工具 参考链接: https://nmap.org/man/zh/ http://www.360doc.com/content/18/0127/18/52402560_7255744 ...
- 列举两种不同类型的Java标识注释,并解释它们之间的区别。
列举两种不同类型的Java标识注释,并解释它们之间的区别.
- 论文笔记系列-Speeding Up Automatic Hyperparameter Optimization of Deep Neural Networks by Extrapolation of Learning Curves
I. 背景介绍 1. 学习曲线(Learning Curve) 我们都知道在手工调试模型的参数的时候,我们并不会每次都等到模型迭代完后再修改超参数,而是待模型训练了一定的epoch次数后,通过观察学习 ...
- 生产者消费者模型java
马士兵老师的生产者消费者模型,我感觉理解了生产者消费者模型,基本懂了一半多线程. public class ProducerConsumer { public static void main(Str ...
- LwIP Application Developers Manual6---Application API layers
1.前言 lwIP提供3种应用编程接口来跟TCP/IP内核通信,如下所示: 低水平的内核/回调或raw API 2个高水平序列API: 1) netconn API 2) socket API(为了兼 ...
- ubuntu14.04上引入thinkphp5类库遇到的一个问题
ubuntu14.04 上加载OSS\OssClient() ;--->在vendor文件夹下的文件要用大写OSS 小写的报错 无法加载类库 Vendor('OSS.autoload');//引 ...
- Unity3D之通过C#使用Advanced CSharp Messenger
Advanced CSharp Messenger 属于C#事件的一种. 维基百科中由详细的说明http://wiki.unity3d.com/index.php?title=Advanced_CSh ...
- oracle 多行变一行 wmsys.wm_concat
背景 还是那个问题,部分程序员喜欢用sql解决问题.发现了这个函数,当初真是大喜过望,现在是哭笑不得.10g支持这个函数,11好像不支持了,而且只有oracle支持,其实自己写个通用方法 ...
- 033_linux操作系统火焰图探测系统性能
火焰图是定位疑难杂症的神器,比如 CPU 占用高.内存泄漏等问题.特别是 Lua 级别的火焰图,可以定位到函数和代码级别. 一.研究 https://moonbingbing.gitbooks.io/ ...