1145:字符串p型编码
时间限制: 1000 ms 内存限制: 65536 KB
提交数: 11401 通过数: 8620
【题目描述】
给定一个完全由数字字符(‘0’,‘1’,‘2’,…,‘9’)构成的字符串str,请写出str的p型编码串。例如:字符串122344111可被描述为"1个1、2个2、1个3、2个4、3个1",因此我们说122344111的p型编码串为1122132431;类似的道理,编码串101可以用来描述1111111111;00000000000可描述为"11个0",因此它的p型编码串即为110;100200300可描述为"1个1、2个 0、1个2、2个0、1个3、2个0",因此它的p型编码串为112012201320。
【输入】
输入仅一行,包含字符串str。每一行字符串最多包含1000个数字字符。
【输出】
输出该字符串对应的p型编码串。
【输入样例】
122344111
【输出样例】
1122132431
【参考代码】
#include <stdio.h> #include <string.h> #define N 510 char s[N]; int main() { int i,len,count=1; gets(s); len=strlen(s); for(i=0;i<len;i++) { if(s[i]==s[i+1]) { count++; } else { printf("%d%c",count,s[i]); count =1; } } return 0; }
http://ybt.ssoier.cn:8088/problem_show.php?pid=1145