Problem Descriptiongiven A string containing only ' a '-' Z ', we could encode it using the following method:
1. Each sub-string containing k same characters should being encodedto "KX" where "X" is the only character in this Sub-strin G.
2. If the length of the sub-string is 1, ' 1 ' should beignored.
Inputthe first line contains an integer N (1 <= n<=) which indicates the number of test cases. The next n lines contain n strings. Each string consists of only ' A '-' Z ' and the length are less than 10000.
Outputfor each test case, output the encoded string in Aline.
Sample INPUT2ABCABBCCC
Sample outputabca2b3c #include <cstdlib>
#include <iostream>
#include <string>
using namespace Std;
int main (int argc, char *argv[])
{
int n,len,num,i;
cin>>n;
string S;
char temp;
while (n--)
{
cin>>s;
Len=s.length ();
Temp=s[0];
Num=1;;
for (i=1;i<len;i++)
{
if (Temp==s[i])
num++;
Else
{
if (num!=1)
cout<<num<<temp;
Else
cout<<temp;
Num=1;
Temp=s[i];
}
}
if (num!=1)
cout<<num<<temp;
Else
cout<<temp;
cout<<endl;
}
System ("PAUSE");
return exit_success;
}
Hangzhou Electric 1020-encoding