24h購物| | PChome| 登入
2012-05-06 18:45:19| 人氣2,628| 回應0 | 上一篇 | 下一篇

[UVA][EASY] 11541 - Decoding

推薦 0 收藏 0 轉貼0 訂閱站台

Problem D
Decoding
Input: Standard Input

Output: Standard Output

 

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 won’t have a length greater than 200 and it will only consist of upper case alphabets.

 

Sample Input                              Output for Sample Input

3

A2B4D1A2

A12

A1B1C1D1

Case 1: AABBBBDAA

Case 2: AAAAAAAAAAAA

Case 3: ABCD

 

#include <stdio.h>

int main() {
    int t, Case = 0;
    char str[205];
    scanf("%d", &t);
    while(t--) {
        scanf("%s", str);
        printf("Case %d: ", ++Case);
        int i, tmp = 0;
        char ch;
        for(i = 0; str[i]; i++) {
            if(str[i] >= 'A' && str[i] <= 'Z') {
                while(tmp)
                    putchar(ch), tmp--;
                ch = str[i];
            } else {
                tmp = tmp*10 + str[i]-'0';
            }
        }
        while(tmp)
            putchar(ch), tmp--;
        puts("");
    }
    return 0;
}

台長: Morris
人氣(2,628) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 10879 - Code Refactoring
此分類上一篇:[UVA][Tree] 12458 - Oh, my trees!

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文