Showing posts with label Volume 115 (11500-11599). Show all posts
Showing posts with label Volume 115 (11500-11599). Show all posts

Monday, December 23, 2013

11547 - Automatic Answer

Problem A

AUTOMATIC ANSWER

Last month Alice nonchalantly entered her name in a draw for a Tapmaster 4000. Upon checking her mail today, she found a letter that read:
“Congratulations, Alice! You have won a Tapmaster 4000. To claim your prize, you must answer the following skill testing question.”
Alice’s initial feelings of surprised joy turned quickly to those of dismay. Her lifetime record for skill testing questions is an abysmal 3 right and 42 wrong.
Mad Skills, the leading skill testing question development company, was hired to provide skill testing questions for this particular Tapmaster 4000 draw. They decided to create a different skill testing question to each winner so that the winners could not collaborate to answer the question.
Can you help Alice win the Tapmaster 4000 by solving the skill testing question?
Program Input
The input begins with t (1 ≤ t ≤ 100), the number of test cases. Each test case contains an integer n (-1000 ≤ n ≤ 1000) on a line by itself. This n should be substituted into the skill testing question below.
Program Output
For each test case, output the answer to the following skill testing question on a line by itself: “Multiply n by 567, then divide the result by 9, then add 7492, then multiply by 235, then divide by 47, then subtract 498. What is the digit in the tens column?”
Sample Input & Output
INPUT
2
637
-120
OUTPUT
1
3

Calgary Collegiate Programming Contest 2008
Solution:  
#include <stdio.h>
int main() {
    int n, T;
    scanf("%d", &T);
    while(T--){
        scanf("%d", &n);
        n = (n*63+7492)*5-498;
        printf("%d\n", n < 0 ? (-n/10)%10 : (n/10)%10);
    }   
    return 0;
}

11541 - Decoding


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

Problemsetter: Sohel Hafiz
Special Thanks to: Mohammad Mahmudur Rahman

Solution:
#include <stdio.h>
#include <ctype.h>
#define MAX 201

int main(){
    static int T, t, i, j, k, K, f;
    static char c,d, S[MAX], R[MAX];
    /*freopen("in11541.txt", "r", stdin);*/
    scanf("%d\n", &T);
    for(t = 1; t <= T; t++){      
        scanf("%s", S);      
        for(i = 0, f = k = K = 0; (c = S[i]) != '\0'; i++){
            if(isalpha(c)){
                if(f == 2){
                    for(j = 0; j < k; j++)
                        R[K++] = d;
                    k = 0;                  
                }
                f = 1;  
                d = c;                              
            }else{
                k = k*10+(c-'0');
                f = 2;
            }          
        }  
        if(k)
            for(j = 0; j < k; j++)
                R[K++] = d;
        R[K] = '\0';      
        printf("Case %d: %s\n", t, R);
    }
    return 0;
}