hdu 1004 Let the Balloon Rise map的应用
来源:互联网 发布:儿童手势识别算法 编辑:程序博客网 时间:2024/05/21 15:38
Let the Balloon Rise
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 44434 Accepted Submission(s): 15730
Problem Description
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.
This year, they decide to leave this lovely job to you.
Input
Input 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.
A test case with N = 0 terminates the input and this test case is not to be processed.
Output
For 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
5greenredblueredred3pinkorangepink0
Sample Output
redpink
Author
WU, Jiazhi
Source
ZJCPC2004
Recommend
JGShining
题意: 输出串出现次数最多的那个 数据保证答案只有一个
思路 map数组 直接搞定
我的第一个做法 map 里面用 string int string是对应的串 而 int是串的编号 那么只要对编号对于的数组a 进行加加炒作 然后遍历数组a找到最大的 对应的编号
根据编号找出 string
题意: 输出串出现次数最多的那个 数据保证答案只有一个
思路 map数组 直接搞定
我的第一个做法 map 里面用 string int string是对应的串 而 int是串的编号 那么只要对编号对于的数组a 进行加加炒作 然后遍历数组a找到最大的 对应的编号
根据编号找出 string
#include<stdio.h>#include<map>#include<iostream>#include<string.h>#include<string>using namespace std;int main(){int a[1005];int n,i,j,cnt,pos,max;string b;while(scanf("%d",&n)!=EOF){cnt=0;memset(a,0,sizeof(a));map<string,int>mp;map<string,int >::iterator it;if(!n) break;while(n--){cin>>b;it=mp.find(b);if(it!=mp.end()){pos=it->second;a[pos]++;}else{cnt++;a[cnt]++;mp[b]=cnt;}}max=0;pos=0;for(i=1;i<=cnt;i++){if(max<a[i]) {max=a[i];pos=i;}}//printf("max=%d poa=%d\n",max,pos);for(it=mp.begin();it!=mp.end();it++){if(it->second==pos){cout<<it->first<<endl; break;}}}return 0;}
这个方法比上面的重要
#include<iostream>#include<map>#include<string>using namespace std;int main(){ int n; string s; while(cin>>n&&n) { map<string,int> mp; for (int i=0; i<n; i++) //直接记数 { cin>>s; mp[s]++;//我个人感觉 这里指的是 s串对应的i 从原来的变成了i+1 而且自动初始化为0 } map<string,int>::iterator it; int max =-1; for (it=mp.begin();it!=mp.end();it++) //找出最大记数 { if(it->second>max) { max=it->second; } }//printf("%d\n",max); for(it=mp.begin();it!=mp.end();it++) //最大记数位置 { if(it->second==max) { cout<<it->first<<endl; } } } return 0;}
- hdu 1004 Let the Balloon Rise map的应用
- HDU 1004 Let the Balloon Rise Map的应用
- map容器的应用:hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise【Map】
- hdu 1004 Let the Balloon Rise map
- HDU 1004 Let the Balloon Rise(map)
- HDU 1004 Let the Balloon Rise map
- Hdu 1004 (Let the Balloon Rise) 简单的map应用
- SDNU 1125 HDU 1004 Let the Balloon Rise【用map做水题】【map应用】 【8月14】
- 【map热手题】HDU 1004—Let the Balloon Rise
- HDU-1004 Let the Balloon Rise(STL: map)
- HDU 1004 Let the Balloon Rise(Map)
- Hdu 1004 Let the Balloon Rise map解决方法
- HDU-#1004 Let the Balloon Rise(字符串+map)
- HDU 1004 Let the Balloon Rise(STL之map)
- HDU 1004 Let the Balloon Rise (map使用)
- 【hdu 1004】Let the Balloon Rise(map)
- HDU 1004 Let the Balloon Rise (map使用)
- java反射机制
- Something about Mutex
- 文件传输 客户端
- SDL 显示核心 SDL_Surface 操作
- 无向图的最短路径求解算法之——Dijkstra算法
- hdu 1004 Let the Balloon Rise map的应用
- 在java中生成二维码,并直接输出到jsp页面
- Java读取MP3文件的二进制数据内附带的信息
- hdu 3174 logo (已知角度求点)
- 如何学习Oracle-eygle的方法经验谈---当你感觉到迷茫时读一下
- VS2010中MFC连接Sql Server 2012方法
- 实习第三周
- 【每日N题】如何判断两个单链表相交?第一个交点在哪里?
- YYXT之IT工作小记(三)