Practice Session: ACM-ICPC Thailand Southern Programming Contest 2012 Prince of Songkla University Hatyai, Thailand

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

ACM-ICPC Thailand Southern Programming Contest 2012

Prince of Songkla University Hatyai, Thailand

Practice Session
11 August 2012
You have 40 minutes and 4 problems to solve.
The input and output of all programs are standard input and standard output.

Problem A. Range
Write a program to find the range of the input integers. The range is the difference
between minimum and maximum values.
Input and Output
The input contains any number of integers, one in a line. You can assume that there will be less
than one million numbers in the input and no integer has absolute value greater than one million.
Then print out the range of the input set.
Sample Input

Sample Output
36

25
-10
18
-4
26

Problem B. Calculation Skill Test


(from UVa 11547 - Automatic Answer)
Write a program for testing the calculation skill.
Input and Output
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.
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
2
637
-120

Sample output
1
3

Hint

Problem C. Summing Digits


(from UVa 11332 Summing Digits)
For a positive integer n, let f(n) denote the sum of the digits of n when represented in
base 10. It is easy to see that the sequence of numbers n, f(n), f(f(n)), f(f(f(n))), ... eventually
becomes a single digit number that repeats forever. Let this single digit be denoted g(n).
For example, consider n = 1234567892. Then:
f(n) = 1+2+3+4+5+6+7+8+9+2 = 47
f(f(n)) = 4+7 = 11
f(f(f(n))) = 1+1 = 2
Therefore, g(1234567892) = 2.
Input
Each line of input contains a single positive integer n at most 2,000,000,000.
Input is terminated by n = 0 which should not be processed.
Output
For each such integer, you are to output a single line containing g(n).
Sample input
2
11
47
1234567892
999999998
0

Sample output
2
2
2
2
8

Problem D. Most Frequent Letter


Find the letter (a-z) that appears most frequently in a text. The lower-case letter and the
upper-case letter are counted as the same letter (for example a = A, b = B).
Input
The input text may contain several lines. Each line can contain at most 250 characters.
Output
Print out the most frequent letter (lower-case) and its frequency, separated by a single space.
If there exist more than one letter, print only the first one in alphabetic order.
Sample Input
Sunday Monday Tuesday
12345678911111111.

Sample Output
a 3

You might also like