UVA11541 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

问题链接UVA11541 Decoding
问题简述:(略)
问题分析
    文本处理题,用到若干编程技巧,包括指针、函数sscanf()和整数位数的计算(值为num的整数,其10进制位数为(int)log10(num))的使用。
    。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA11541 Decoding */

#include <bits/stdc++.h>

using namespace std;

const int N = 200;
char s[N + 1];

int main()
{
    int t, caseno = 0, num;
    scanf("%d", &t);
    while(t--) {
        printf("Case %d: ", ++caseno);
        scanf("%s", s);
        char *p = s;
        while(*p) {
            sscanf(p + 1, "%d", &num);
            for(int i = 1; i <= num; i++)
                putchar(*p);
            p += (int)log10(num) + 2;
        }
        putchar('\n');
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值