HDOJ 1004 Let the Balloon Rise
2017-01-24 13:57
344 查看
最近重新开始了刷题的道路,也开始搭建自己的博客,第一次写,写的不好多多见谅。
AC代码如下:
反思:学会掌握思路,弄清每一个变量的意义还有边界,Debug、Debug再Debug,最后就是不停的测试啦,大家加油!
问题描述
题目比较简单,就是统计字符串的次数算法
不需要什么特殊的算法,就是人工统计算法的代码实现,具体思想:每一次读取新的字符串时从之前所有的字符串里面进行搜索,如果已经存在,则该字符串次数加一,最后将次数最多的字符串输出即可数据结构
一个二维数组保存字符串,一个一维数组保存出现次数AC代码如下:
include <iostream> include <string.h> using namespace std; int main() { int n; char ballon[1000][16]; int count[1000]; //记录气球的次数 char temp[16]; while (1){ cin >> n; if (n==0) break; memset(count,0,1000); cin >> temp; strcpy(ballon[0] , temp); count[0] = 1; for (int i = 1; i <n ; ++i) { cin >> temp; strcpy(ballon[i],temp); for (int j = 0; j <i ; ++j) { if (strcmp(ballon[j],temp)==0) count[i]++; } } int max=0; //保存最大的次数 for (int k = 0; k <n ; ++k) { if (max < count[k]) max = count[k]; } int t; //找到最大次数的索引,并将原数组中的字符串输出 for (int i=0; i<n; i++){ if (count[i]==max) t = i; } cout << ballon[t] << endl; } }
反思:学会掌握思路,弄清每一个变量的意义还有边界,Debug、Debug再Debug,最后就是不停的测试啦,大家加油!
相关文章推荐
- hdoj 1004 Let the Balloon Rise
- HDOJ1004 Let the Balloon Rise(字符串——次数统计)
- HDOJ 1004 Let the Balloon Rise
- hdoj 1004 Let the Balloon Rise(map)
- 【HDOJ】【1004】Let the Balloon Rise
- hdoj 1004 Let the Balloon Rise 【STL or 暴力】
- HDOJ杭电1004 Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise (map)
- [简单题][hdoj_1004]Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise(字符串)
- HDOJ 1004 Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise
- HDOJ Let the Balloon Rise 1004
- ACM--模拟--气球出现次数--HDOJ 1004--Let the Balloon Rise--水
- HDOJ-1004 Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise
- hdoj 1004 Let the Balloon Rise 解题报告
- hdoj 1004 Let the Balloon Rise(模拟 || 字典树)