Problem Description

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.

Input

The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only ‘A’ - ‘Z’ and the length is less than 10000.

Output

For each test case, output the encoded string in a line.

Sample Input

2
ABC
ABBCCC

Sample Output

ABC
A2B3C

题目大意:

输入一个数表示有几组测试数据,接下来输入字符串只包含A到Z,每个子字符串包含k相同的字符编码。如果子字符串的长度为1,则应忽略“1”。输出时为k字符子串。如输入为WWEERWW,则输出为2W2ER2W。

c++

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    int a,b,c,d,e;
    char m[10005];
    cin>>a;
    while(a--)
    {
        cin>>m;
        for(b=0;m[b]!='\0';)
        {
            c=1;
            while(m[b]==m[b+1])    //判断相邻字符是否相等,不相等时结束。
            {
                c++;
                b++;
            }
            if(c==1)
            cout<<m[b];
            else
            cout<<c<<m[b];
            b++;
        }
        cout << endl;
    }
    return 0;
}