杭电HDU 1004 Let the Balloon Rise AC代码 简单题
来源:互联网 发布:模型制作 软件 编辑:程序博客网 时间:2024/06/05 02:30
题目很简单,大致意思是有多组测试数据,每组测试数据里找出出现次数最多的字符串,输入0结束。这个题没什么坑点,而且题目说了是唯一解。
用了结构体,algorithm里的sort函数就解决了,贴 C++的AC代码如下:
(PS:渣渣的第二贴,有改正或意见欢迎指出!)
#include<iostream>#include<cstring>#include<algorithm>using namespace std;struct ballons{public: char color[20]; int time = 1;//出现的次数};bool cmp(ballons a, ballons b){ return a.time > b.time; // >= 是错的}int main(){ int T; while (~scanf("%d", &T)&&T) { int i, j; int num=0; //不同颜色的气球个数 bool flag = false; //flag:判断该颜色是否出现过 ballons b[1001]; for (i = 0; i < T; i++) { char save[20]; scanf("%s", save); for (j = 0; j < num; j++) { if (strcmp(b[j].color, save) == 0) //之前出现过 { b[j].time++; //次数+1 flag = true; } } if (flag == false)//之间没有出现过 储存到结构体数组中 strcpy(b[num++].color, save); else flag = false;//这儿之前忘了 不要再粗心啦 } sort(b, b + num, cmp); printf("%s\n", b[0].color); } return 0;}
阅读全文
0 0
- 杭电HDU 1004 Let the Balloon Rise AC代码 简单题
- 杭电 1004[Let the Balloon Rise]
- 杭电 1004 Let the Balloon Rise
- 杭电 1004 Let the Balloon Rise
- 杭电 1004 Let the Balloon Rise
- 杭电1004 Let the Balloon Rise
- 杭电-1004 Let the Balloon Rise
- 杭电1004---Let the Balloon Rise
- 杭电1004-Let the Balloon Rise
- 【杭电】 1004 Let the Balloon Rise
- 杭电 1004 Let the Balloon Rise
- 杭电1004 Let the Balloon Rise
- [杭电]Let the Balloon Rise
- 杭电Let the Balloon Rise
- 杭电OJ Let the Balloon Rise
- 杭电problem1004- Let the Balloon Rise
- hdu 1004 Let the Balloon Rise ( 字符串简单处理)
- Let the Balloon Rise(杭电ACM 1004)
- 鼓励自己
- display:none与visible:hidden的区别
- CSS3
- 使用注解来构造IoC容器
- hdu1174(点到直线的距离)
- 杭电HDU 1004 Let the Balloon Rise AC代码 简单题
- java汉字首字母提取
- React学习(六)PropTypes
- react native 组件汇总整理,点击链接至GitHub
- 服务机器人其最大的问题:定位导航
- 一维数组 冒泡排序 shell 排序 二分查找 C++
- 如何导出和导入mysql数据(数据迁移)
- 4.spring容器高级主题
- mysql null判断