模拟题,trick很多。。。
#include <stdio.h>
#include <string.h>
char str[1000];
int main()
{
memset(str, 0, sizeof(str));
while ( !feof(stdin) )
{
gets(str);
if (!str[0])
{
putchar(10);
continue;
}
int i, j;
for ( i = 0 ; str[i] ; i++ )
{
if (str[i] == str[i+1])
{
for ( j = i ; str[i] == str[i+1] && (i-j) < 8 ; i++ );
printf("%d%c", i-j+1, str[i]);
}
else
{
printf("1");
for ( j = i ; str[i] != str[i+1] && str[i] ; i++ )
{
if ('1' == str[i]) printf("1");
printf("%c", str[i]);
}
printf("1");
if ( str[i] == str[i+1]) i--;
}
}
putchar(10);
memset(str, 0, sizeof(str));
}
return 0;
}