题意需要稍微理解一下。
如果是连续的数就打印他的长度和字符,但不能超过九个
如果是不连续的,那么就在这段不连续的字符两边各打印一个1,如果是是字符1就打印11,否则打印字符本身
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 1100;
char str[N], s[N];
int a[N];
int main(){
while(gets(str)){
int cnt = 0;
bool sig = 0;
for(int i = 0; str[i]; i++){
int j = i;
while(str[j] == str[i] && j - i < 9)
j++;
a[cnt] = j - i;
s[cnt++] = str[i];
i = j - 1;
}
for(int i = 0; i < cnt; i++){
if(a[i] == 1){
if(!sig)
printf("1");
sig = 1;
if(s[i] == '1')
printf("1");
printf("%c", s[i]);
}
else{
if(sig)
printf("1");
sig = false;
printf("%d%c", a[i], s[i]);
}
}
if(sig)
printf("1");
puts("");
}
return 0;
}