Encoding
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12989 Accepted Submission(s): 5502
1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.
2. If the length of the sub-string is 1, '1' should be ignored.
#include<string.h>
#include<stdio.h>
int main ()
{
int t ;
char str[10005];
while( scanf("%d" , &t ) != EOF )
{
while( t-- )
{
scanf("%s" , str);
int len = strlen ( str );
for( int i = 0 ; i < len ; i++ )
{
int hh = 1 ;
for( int j = i+1 ; j < len ; j++ )
if( str[i] == str[j] )hh++;
else break;
if( hh > 1 )
printf("%d%c", hh , str[i] );
else
printf("%c" , str[i]);
i +=(hh-1);//從下一個不重複的字母開始
}
puts("");
}
}
return 0;
}