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 ...
随机推荐
- IDEA Spring注入显示红色波浪线
- Linux中find命令的用法汇总
Linux中find命令的用法汇总 https://www.jb51.net/article/108198.htm
- Deep Neural Networks for Object Detection(翻译)
0 - Abstract 深度神经网络(DNNs)最近在图像分类任务上表现出了突出的性能.在这篇文章中,我们进一步深入探究使用DNNs进行目标检测的问题,这个问题不仅需要对物体进行分类,并且还需要对各 ...
- java中有哪4种整形数据类型?它们有什么不同之处?
java中有哪4种整形数据类型?它们有什么不同之处? (byte.short.int和long型)最大值和最小值都不一样.
- UVA315 Network 连通图割点
题目大意:有向图求割点 题目思路: 一个点u为割点时当且仅当满足两个两个条件之一: 1.该点为根节点且至少有两个子节点 2.u不为树根,且满足存在(u,v)为树枝边(或称 父子边,即u为v在搜索树中的 ...
- SpringCloud知识点20190313
1.SpringBoot和SpringCloud的关系(面试题) Spring Boot 可以离开 Spring Cloud 单独使用开发项目,但是Spring Cloud离不开SpringBoot, ...
- RedisGeo
redis3.2版本增加了对GEO(地理位置)的支持 操作命令 geoadd(String key, Double longitude, Double latitude, String member) ...
- 使用服务器参数文件(SPFILE)管理初始化参数
传统上,Oracle数据库的初始化参数存储在文本初始化参数文件中.为了更好的可管理性,您可以选择在二进制服务器参数文件中维护初始化参数,该文件在数据库启动和关闭期间保持不变.本节介绍服务器参数文件,并 ...
- CF1096E The Top Scorer
题目地址:洛谷CF1096E 本场AC数最少 (最难) 的题目 题目大意:给出三个数p , s,r,表示有p人,每个人都有一个非负得分,所有人的得分和为s,Hasan的得分至少为r,求Hasan是第一 ...
- webgl开发中添加IIS的mime类型
1.在iis中直接设置 .obj application/octet-stream .mtl application/octet-stream 2.在配置文件中加 <?xml version=& ...