码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1020 Encoding

时间:2020-03-04 00:28:32      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:while   des   less   contain   out   following   OWIN   enc   line   

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
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

const double inf=1e20;
const int maxn=1e5+10;
const int mod=1e9+7;

char a[maxn];
char s[maxn];
int num[maxn];

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%s",a);
        int len=strlen(a);
        int j=0;
        s[0]=a[0];
        num[0]=1;
        for(int i=1;i<len;i++){
            if(a[i]==s[j])num[j]++;
            else {
                s[++j]=a[i];
                num[j]=1;
            }
        }
        for(int i=0;i<=j;i++){
            if(num[i]!=1){
                printf("%d",num[i]);
            }
            printf("%c",s[i]);
        }printf("\n");
    }
    return 0;
}

 

hdu 1020 Encoding

标签:while   des   less   contain   out   following   OWIN   enc   line   

原文地址:https://www.cnblogs.com/wz-archer/p/12405531.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!