Wednesday, July 1, 2009
73. The Haredst Problem ever
|
IntroductionJulius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first ciphers. This cipher was so incredibly sound, that no one could figure it out without knowing how it worked. You are a sub captain of Caesar's army. It is your job to decipher the messages sent by Caesar and provide to your general. The code is simple. For each letter in a plaintext message, you shift it five places to the right to create the secure message (i.e., if the letter is 'A', the cipher text would be 'F'). Since you are creating plain text out of Caesar's messages, you will do the opposite:
Cipher text Only letters are shifted in this cipher. Any non-alphabetical character should remain the same, and all alphabetical characters will be upper case.
InputInput to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. All characters will be uppercase.
Following the final data set will be a single line, "ENDOFINPUT".
OutputFor each data set, there will be exactly one line of output. This is the original message by Caesar.
Sample Input
START
Sample Output
IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES
|
72.Long Multiplication
Problem 1 -- Long Multiplication -- Filename LONGMULT
In traditional "long multiplication" we determine the product of two integers, x and y, by multiplying x and the individual digits of y, in turn, starting with the units digit. The results of these multiplications are arranged appropriately and added, yielding the completed product. The representation of these operations is usually done in a particular manner. Consider the multiplication of 123 by 95: 123
95
---
615
1107
-----
11685
The numbers to be multiplied, x and y, are each displayed on a separate line, followed by a horizontal line. The results of multiplying each digit of y by x are then displayed on separate lines, followed by another horizontal line, and then the final product. In this problem you are to perform a sequence of such multiplications, displaying the results in this traditional representation. Input
Each line of the input data, except the last, will contain two integers, x and y, separated by whitespace (one or more blanks and tab characters). Whitespace may also precede the first integer and follow the second integer. Each integer will have no more than 10 digits. The last line of the input data will contain only whitespace, and marks the end of the input.Output
For each pair of integers (that is, each input line except the last), perform the multiplication of x by y, displaying the results in the form shown above and in the examples shown below. Follow the output for each multiplication by a blank line. If y contains only a single significant digit, omit the second horizontal line and the sum (since in that case it would be superfluous). Display 0 digits only when they are significant. The number of hyphens in the first horizontal line should be the same as the number of digits in the larger of x and y. The number of hyphens in the second horizontal line, if it is produced, should be the same as the number of digits in the product of x and y.Example Input
4 7
135 46
12345 862
this line is blank
Expected Output
4
7
-
28
135
46
---
810
540
----
6210
12345
862
-----
24690
74070
98760
--------
10641390
Saturday, June 27, 2009
71. Asked in Hello World(Algorythm '09)
Problem - Sum of Consecutive Prime Numbers
--------------------------------------------
Some positive integers can be represented by a sum of one or more
consecutive prime numbers. How many such representations does a given
positive integer have? For example, the integer 53 has two
representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three
representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The
integer 3 has only one representation, which is 3. The integer 20 has no
such representations. Note that the summands must be consecutive prime
numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation
for the integer 20.
Your mission is to write a program that reports the number of
representations for the given positive integer.
Input
-----
The input is a sequence of positive integers each in a separate line.
The integers are between 2 and 10000, inclusive. The end of the input
is indicated by a zero.
Output
------
The output should be composed of lines each corresponding to an input
line except the last zero. An output line includes the number of
representations for the input integer as the sum of one or more
consecutive prime numbers. No other characters should be inserted in the
output.
Sample Input
------------
2
3
17
41
20
666
12
53
0
Output for Sample Input
-----------------------
1
1
2
3
0
0
1
2
