hdu_1002_Let the Balloon Rise (模拟)
来源:互联网 发布:win7 apache php 配置 编辑:程序博客网 时间:2024/06/06 02:14
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004
题意:输入n个气球的颜色,(气球的颜色是一个字符串,最多有15个小写字母),输出最多相同颜色气球的颜色,输入0结束程序。
保证每组数据都有唯一且具有最多的一种颜色的气球。
解题思路:利用string类型的数组保存n个气球的颜色
样例:
1)a b a d e
2)a b a d e
a->a b a d e
b->a b a d e
c->a b a d e
d->a b a d e
1)中的每个元素与2)中的每个元素比较,相等则cnt++,且最终把最大的元素个数保存在word中。
记录最大元素个数的下标,保存在flag中。
<span style="font-size:18px;">#include <iostream>#include <string>using namespace std;int main(int argc, char *argv[]){int n;string color[1010];//string类型的数组 while(1){string color[1010] = {""};//初始化为空的数组,没有这个初始化会WA cin >> n;if(n == 0)return 0;for(int i = 0;i < n;i++){cin >> color[i];}int cnt,flag = 10000;intword = 0;for(int i = 0;i < n;i++){cnt = 0;for(int j = 0;j < n;j++){if(color[i] == color[j]){cnt++;//元素相等则++ }}if(cnt > word){word = cnt;//最大的元素个数保存在word中 flag = i;//记录最大元素个数的下标}}cout << color[flag] << endl; }return 0;}</span>
0 0
- hdu_1002_Let the Balloon Rise (模拟)
- (hdu1004)Let the Balloon Rise
- Let the Balloon Rise(HDU1004)
- HDOJ Let the Balloon Rise(java)
- Let the Balloon Rise(Map容器)
- Let the Balloon Rise(HDU OJ1004)
- HDU(1004)Let the Balloon Rise
- (ACM)Let the Balloon Rise
- ZOJ_2104_Let the Balloon Rise
- Hdu_1004_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
- BlockingQueue详解
- Leetcode Wildcard Matching
- 同步时钟脚本在crontab中遇到的问题
- linux shell中各种括号的使用方法
- 科大少年班“神童”是先戴博士帽,还是先戴乌纱帽?
- hdu_1002_Let the Balloon Rise (模拟)
- 科大少年班“神童”是先戴博士帽,还是先戴乌纱帽?
- stm8 红外解码 使用TL IO中断与定时实现(芯片用103)
- 为mysql ibdata1瘦身
- 关于wifi AP模式(热点Hotpot) ip地址的相关信息
- 快速排序
- Android使用Ant批量打包
- 第17周【项目 4 - 日期结构体】(2)
- android的bitmap——1