Hangzhou Electric 1020-encoding

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.