/* 简单题,统计气球数最多的颜色 */ #include <stdio.h> #define SIZE_ROW 1001 #define SIZE_COL 16 int main() { int N; int i; char colors[SIZE_ROW][SIZE_COL]; char color[SIZE_COL]; //存储气球颜色数 int colorNum; //统计不同颜色气球个数 int balloon[SIZE_ROW]; //用于返回重复颜色气球的下标 int result; //颜色对多的气球个数 int max; //颜色最多的气球个数的下标 int maxIndex; //freopen("F:\\input.txt", "r", stdin); while ((scanf("%d", &N) == 1) && N != 0) { colorNum = 0; memset(balloon, 0, sizeof(balloon)); memset(colors,0,sizeof(colors)); for (i = 0; i < N; i++) { scanf("%s", color); //搜索颜色数组,如果没有当前输入的颜色,则将该颜色插入颜色数组。否则,对应的气球数+1 result = searchColor(color, colors, colorNum, balloon); if (result == -1) { strcpy(colors[colorNum], color); balloon[colorNum]++; colorNum++; } else balloon[result]++; } max = balloon[0]; maxIndex = 0; //寻找气球数最多的颜色 for (i = 1; i < colorNum; i++) { if (max < balloon[i]) { max = balloon[i]; maxIndex = i; } } printf("%s\n", colors[maxIndex]); } //freopen("con", "r", stdin); //system("pause"); return 0; } int searchColor(char color[], char colors[][SIZE_COL], int colorNum, int balloon[]) { int i; for (i = 0; i < colorNum; i++) { if (strcmp(color, colors[i]) == 0) return i; } return -1; }
R语言与数据分析【第一季】
学院
2015年04月18日 14:06
杭电ACM-HDU1004-Let the Balloon Rise
题目来自杭电ACM: acm.hdu.edu.cn Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory ...
(解题报告)HDU1004---Let the Balloon Rise
Let the Balloon RiseTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe...
ACM--模拟--气球出现次数--HDOJ 1004--Let the Balloon Rise--水
HDOJ题目地址:传送门 Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536...
【map热手题】HDU 1004—Let the Balloon Rise
题目:点击打开链接 建议初学STL的人用MAP来切这道水题,可以对MAP的方便之处有更加深刻的理解。 因为调用和查找的确挺简单的。效率据查阅资料,是lgN. #include #include...
ACM Let the Balloon Rise
Let the Balloon Rise Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Othe...
Let the Balloon Rise(STL的map)
Link: ZOJ Problem Set - 2104 Let the Balloon Rise Time Limit: 2 Seconds Memory L...

没有更多推荐了,返回首页