HDU 1004 Let the Balloon Rise

来源:互联网 发布:逆袭网络剧完整版 编辑:程序博客网 时间:2024/04/30 01:37

题目链接:Let the Balloon Rise

解题思路:直接用STL就可以做出来,用map的映射,形成一对一的关系。

#include<stdio.h>#include<string.h>#include<string>#include<map>using namespace std;int main(){string asd;char color[20]; int i, n, max, index;while(scanf("%d", &n) && n){max = -1;map<string, int> ball;getchar();for(i = 0; i < n; i++){scanf("%s", &color);asd = string(color); ball[asd]++;}for(map<string, int>::iterator it = ball.begin(); it != ball.end(); it++){if(it->second > max){max = it->second;asd = it->first;}}printf("%s\n", asd.c_str());}return 0;} 


原创粉丝点击