Let the Balloon Rise 选出最受欢迎的色彩
来源:互联网 发布:正规淘宝网上兼职 编辑:程序博客网 时间:2024/06/10 02:47
/*
输入的第一个数为投票人数,输入0结束。然后进行投票,选出最受欢迎的色彩。
sample input
5
green
red
blue
red
red
3
pink
orange
pink
0
sample output
red
pink
*/
code:
#include<stdio.h>
#include<string.h>
typedef struct chars {
char ch[20];
int num;
}Chars;
int main() {
int i,j,k,n;
Chars chs[1000];
char col[20];
while(scanf("%d",&n)==1){
if(n==0)break;
k=0;
while(n) {
scanf("%s",col);
if(k==0){
strcpy(chs[k].ch,col);
chs[k].num=1;
k++;
} else {
for(i=0;i<k;i++){
if(strcmp(chs[i].ch,col)==0){
chs[i].num++;
break;
}
}
if(i==k){
strcpy(chs[k].ch,col);
chs[k].num=1;
k++;
}
}
n--;
}
j=0;
for(i=0;i<k;i++)
if(chs[i].num>chs[j].num)j=i;
printf("%s\n",chs[j].ch);
}
}
- Let the Balloon Rise 选出最受欢迎的色彩
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the balloon rise
- Let the Balloon Rise
- Let the Balloon Rise
- Let the Balloon Rise
- 黑马程序员--java高新技术--java5的枚举
- PL/SQL Profiling
- 常用校验方式
- TCP与UDP的区别,以及它们各自的定义
- 使用Add-in向选中的Slide插入文字
- Let the Balloon Rise 选出最受欢迎的色彩
- WAS7 下如何删除错误的BLA
- 淘宝首页的搜索规律 高级搜索页搜索规律 淘宝商家应对的优化策略
- 黑马程序员--java高新技术--反射的深入讲解
- java web培训_北软教育_工作日志_6.21
- 轻轻杨柳风
- iphone--UIImage图片拉伸
- Chapter4 Basic Instructions
- java内部类