Given a string containing only 'A' - 'Z', we could encode it using the following method:
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.
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.
2 ABC ABBCCC
ABC A2B3C
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
char ch;
int T;
cin >> T;
getchar();
while(T--)
{
int f[1050] = {1}, index = 0;
char c[1050];
c[0] = getchar();
char initial = c[0];
while((ch = getchar()) != '\n')
{
if(initial == ch)
{
++f[index];
}
else
{
++index;
initial = ch;
c[index] = ch;
f[index] = 1;
}
}
for(int i = 0; i <= index; ++i)
{
if(f[i] > 1)
cout << f[i];
cout << c[i];
}
cout << endl;
}
}