decoding

Encoding is the process of transforming information from one format into another. There exist several
different types of encoding scheme. In this problem we will talk about a very simple encoding technique;
Run-Length Encoding.
Run-length encoding is a very simple and easy form of data compression in which consecutive
occurrences of the same characters are replaced by a single character followed by its frequency. As an
example, the string ‘AABBBBDAA’ would be encoded to ‘A2B4D1A2’, quotes for clarity.
In this problem, we are interested in decoding strings that were encoded using the above procedure.
Input
The first line of input is an integer T (T < 50) that indicates the number of test cases. Each case is
a line consisting of an encoded string. The string will contain only digits [0-9] and letters [A-Z]. Every
inputted string will be valid. That is, every letter will be followed by 1 or more digits.
Output
For each case, output the case number followed by the decoded string. Adhere to the sample for exact
format.
You may assume the decoded string wont have a length greater than 200 and it will only consist of
upper case alphabets.
Sample Input
3
A2B4D1A2
A12
A1B1C1D1
Sample Output
Case 1: AABBBBDAA
Case 2: AAAAAAAAAAAA
Case 3: ABCD

水题

#include<cstdio>
#include<cstring>
int main(){
    int n;
    char str[105];
    scanf("%d",&n);
    for(int i = 0;i < n;i++){
        scanf("%s",str);
        int len = strlen(str);
        printf("Case %d: ",i+1);
        char tmp;
        for(int j = 0;j < len;j++){
            if(str[j] >= 'A' && str[j] <= 'Z'){
                tmp = str[j];
                int sum = 0;
                j++;
                while(str[j] >= '0' && str[j] <= '9'){
                    sum = sum*10 + str[j] - '0';
                    j++;
                }
                for(int k = 0;k < sum;k++){
                    printf("%c",tmp);
                }
                j--;
            } 
        }
        printf("\n");
    }
    return 0;
}
全部评论

相关推荐

10-23 16:33
门头沟学院 Java
本人某中9本科,成绩中等,目前没科研没实习,目前后端学到了javaWeb,开始没定好方向,在学国外课程,走工程路线起步有点晚了,到这个时间点了还在学JavaWeb,顿感迷茫,不知道是坚持走下去还是寒假去准备考研。考研这个路弄得我还是心痒痒的,因为从众考研的人也不在少数,所以会有这方面的心理安慰吧,就是“不行我可以去考研啊”,而且意味着三年的缓冲,为了复试还有积攒经验美化简历,其实现在也可以去申入实验室打杂;就业可能意味着多些工作经验,工程岗应该到后面还是经验大于学历?还是有点迷茫了,求助好心人有无路线启发
千千倩倩:同27给点建议,现在这个时间点可以快速看完外卖和点评,不用跟着敲,但一定要在看的时候总结每个部分的整个业务流程,对其中的实现有一个大概的印象。然后直接开始看八股,刷算法。八股和算法最好还是在项目学习中穿插着看。如果计算机基础,算法这些基础好,加上每天刻苦学习,两周可以达到勉强能面试的水平,到时候就直接海投中小厂,在约面和面试的过程中不断巩固知识。没找到实习也没关系,就当积累经验。再沉淀一波直接明年三月开始投暑期,毕竟是9本,总是有面试机会的,只要你这三个月不懈怠,面试发挥得一定不错,只要拿到一个中,大厂暑期实习,秋招就有竞争力了。总得而言,现在还有机会,但是时间非常紧张,需要你结合自己情况考虑,共勉
你会选择考研还是直接就业
点赞 评论 收藏
分享
09-24 18:30
已编辑
长春工业大学 产品经理
小肥罗:HR就是好人的缩写哈哈哈哈
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务