HDOJ 1004
Let the Balloon Rise
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 45024 Accepted Submission(s): 15983
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
5
green
red
blue
red
red
3
pink
orange
pink
0
Sample Output
red
pink
1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 5 char ballons[1000][15]; 6 int sum[1000]; 7 int ballons_idx; 8 int n; 9 10 int InBallons(char* tmp) 11 { 12 int i; 13 for (i=0;i<ballons_idx;i++) 14 { 15 if (strcmp(tmp,ballons[i]) == 0) 16 { 17 sum[i]++; 18 return 1; 19 } 20 } 21 return 0; 22 } 23 int FindMax() 24 { 25 int i, max=-1, idx=0; 26 for (i=0;i<ballons_idx;i++) 27 { 28 if (sum[i]>max) 29 { 30 max = sum[i]; 31 idx = i; 32 } 33 } 34 return idx; 35 } 36 void main() 37 { 38 int i; 39 char tmp[15]; 40 scanf("%d",&n); 41 42 while(n) 43 { 44 ballons_idx = 0; 45 memset(sum,0,sizeof(int)*1000); 46 for (i=0;i<n;i++) 47 { 48 scanf("%s",tmp); 49 if (InBallons(tmp) == 0) 50 { 51 strcpy(ballons[ballons_idx++],tmp); 52 } 53 } 54 printf("%s\n",ballons[FindMax()]); 55 scanf("%d",&n); 56 } 57 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!