HDOJ 1004 Let the Balloon Rise
来源:互联网 发布:淘宝宝箱在哪里 编辑:程序博客网 时间:2024/05/19 18:46
最近重新开始了刷题的道路,也开始搭建自己的博客,第一次写,写的不好多多见谅。
问题描述
题目比较简单,就是统计字符串的次数
算法
不需要什么特殊的算法,就是人工统计算法的代码实现,具体思想:每一次读取新的字符串时从之前所有的字符串里面进行搜索,如果已经存在,则该字符串次数加一,最后将次数最多的字符串输出即可
数据结构
一个二维数组保存字符串,一个一维数组保存出现次数
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,最后就是不停的测试啦,大家加油!
1 0
- 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 20140726
- HDOJ Let the Balloon Rise 1004
- 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
- HDOJ 1004 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
- 在centos6.5上离线安装Cloudera Manager 以及CDH
- Linux配置ssh无密码登录
- 第二十一节 类型参数(三)-协变与逆变
- docker 1.13 centos7 mv: can't remove : Directory not empty
- 内外网双网卡.bat启动设置
- HDOJ 1004 Let the Balloon Rise
- [Codeforces Round #310 DIV1A (CF555A)] Case of Matryoshkas
- spidev介绍
- Apache Kafka笔记(三):Producer的工作原理
- 《微信小程序七日谈》- 第六天:小程序devtool隐藏的秘密
- 你不可能没看过这10个设计师的文章
- awk 字段匹配
- 无法定位程序输入点**于动态链接库api-ms-win-crt-runtime-l1-1-0.dll上
- 第二十二节 高级类型 (一)