[水题]HDOJ1020
来源:互联网 发布:迅雷看看优化版 编辑:程序博客网 时间:2024/06/09 15:06
http://acm.hdu.edu.cn/showproblem.php?pid=1020
这道题是个普通的枚举,条理清晰就没问题
如下这段代码,用太多if else就会造成超时
#include <stdio.h>#include <string.h>int main(){ int N,i,n,j; char a[1001]; int count=1; while (scanf ("%d",&N)!=EOF) { for (j=0;j<N;j++){ scanf ("%s",a); n=strlen(a); for (i=1;i<n;i++) if (a[i]==a[i-1]){ count++; if (i==n-1) printf ("%d%c",count,a[i]);} else { if (count==1) printf ("%c",a[i-1]); else printf ("%d%c",count,a[i-1]); count=1; if (i==n-1) printf ("%c",a[i]); count=1;} printf ("\n"); count=1; } } return 0;}
正确的代码
#include <cstdio>#include <string.h>int main(){ int t; char str[10001]; scanf("%d",&t); while(t--){ scanf("%s",str); int count=1; for(int i=0;i<strlen(str);i++){ if(str[i]==str[i+1])count++; else{ if(count==1) printf("%c",str[i]); else printf("%d%c",count,str[i]); count=1; } } printf("\n"); }}
0 0
- [水题]HDOJ1020
- HDOJ1020
- hdoj1020
- hdoj1020
- HDOJ1020
- HDOJ1020 水
- hdoj1020--Encoding
- HDOJ1020 Encoding
- HDOJ1020 Encoding
- hdoj1020 Encoding
- HDOJ1020 Encoding
- HDOJ1020连续字符串
- C语言 hdoj1020
- hdoj1020简单的字符串处理
- 水题
- 水题
- 水题
- 水题
- Struts2学习之Action接收参数方法二(用DomainModel接收参数(模型驱动))
- iOS触摸事件学习
- android中的颜色代码
- Grunt 单独对css压缩并生成min.css文件
- h:panelGrid、h:panelGroup标签学习
- [水题]HDOJ1020
- 模板类的继承
- Caused by: java.lang.IllegalArgumentException: addChild: Child name 'localhost' is not unique
- easy ui jquery 添加时样式出现问题
- jquery+ajax简单例子及jquery事件
- 数据结构——有序线性表的的插入与删除
- iOS sqlite 数据库加密
- A problem of sorting----(BestCoder Round #54 (div.2))
- react-native试玩(33)-状态栏API