HDU 1004 Let the Balloon Rise
来源:互联网 发布:至尊妖孽软件下载 编辑:程序博客网 时间:2024/05/22 01:21
给了一堆颜色,然后找出这一堆颜色中哪一个颜色出现的次数最多,输出这个颜色。我用map存入的各种颜色然后比较出一个最大的,再输出存的这个颜色就好了.....然而不知为何WA了= =暂时没找到错误在哪......先贴出来,以后再翻出来改= =
以下是WA的代码= =
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>using namespace std;char s[1005][105];char e[105];int main(){ int n; int k,i; while(scanf("%d",&n)!=EOF) { map<string,int>m; if(n==0) break; for(i=0;i<n;i++) { scanf("%s",s[i]); } for(i=0;i<n;i++) { m[s[i]]++; } strcpy(e,s[0]); k=m[s[0]]; for(i=0;i<n;i++) { if(m[s[i]]>k) strcpy(e,s[i]); } cout<<e<<endl; } return 0;}
好吧,原来是我前面用的是char数组存的颜色,然后map的key定义的string类型,貌似不能这样用= =然而为何本地编译器能运行,还是对的......总之都改成用string类型就过了......
以下是修改后的AC代码
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>using namespace std;string s;string e;int main(){ int n,t; int k,i; while(scanf("%d",&n)!=EOF) { map<string,int>m; if(n==0) break; for(i=0;i<n;i++) { cin>>s; m[s]++; } t=0; map<string,int>::iterator p; for(p=m.begin();p!=m.end();p++) { if(p->second>t) { t=p->second; e=p->first; } } cout<<e<<endl; } return 0;}
0 0
- HDU 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU--1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- Hdu 1004 - Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise
- HDU--1004--Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- hdu 1004 Let the Balloon Rise
- HDU 1004 Let the Balloon Rise STL
- 李新:搜索引擎竞价推广要变成“广告”了 可能会是这样的
- MySQL数据表列属性操作
- Linux命令之iconv
- php——读写文件操作
- STS配置Maven
- HDU 1004 Let the Balloon Rise
- HDU 4381 Grid
- java基础概念
- angular定义promise异步处理值方式(超简单)
- AlertDialog 攻略 自定义宽度,改变灰色背景透明度
- 暑期dp46道(23)HDOJ 1059 Dividing 多重背包+二进制优化
- 前方车辆检测的常用方法
- LeetCode_OJ【85】 Maximal Rectangle
- 回文串(Manacher)算法粗略讲解