Czech ACM Student Chapter
CTU FEE Prague, MFF UK Prague, FEI TU Ostrava FI MU Brno, FIIT STU Bratislava
## CTU Open 2006## Tree Marking Animals
A Let us return to tree markers. Tree markers climb through the tree randomly, performing the following operations: ## Input SpecificationThe input consists of several instances separated by single empty lines; input of each instance consists of several lines. Each input instance is finished by a line containing a string "All tree markers went for lunch, they will be back at 15:00.". The first line of each instance contains one integer - A string "Mark" followed by an integer
`k`() - a tree marker marks the node`k`. - A string "Unmark" followed by an integer
`k`() - a tree marker unmarks the node`k`. - A string "Jump" followed by an integer
`k`() - a tree marker jumps from the node`k`.
## Output SpecificationFor each input instance, output a single line. This line contains several integers separated by single spaces - for each jump event in the instance, write the number of the node in that the tree marked ends his jump. ## Sample Input5 1 2 3 4 Mark 2 Mark 3 Jump 5 Mark 4 Jump 5 Unmark 2 Jump 5 Unmark 4 Unmark 3 Jump 5 Mark 4 Jump 4 Unmark 4 Jump 4 All tree markers went for lunch, they will be back at 15:00. 1 Jump 1 Mark 1 Jump 1 All tree markers went for lunch, they will be back at 15:00. ## Output for Sample Input3 4 4 1 4 1 1 1 ## Black Boxes
A a_{1}, a_{2}, ..., a_{k} of k pairwise distinct numbers. Two patterns a_{1}, a_{2}, ..., a_{k} and b_{1}, b_{2}, ..., b_{k} are equivalent if for all i and j such that . A dictionary is a list of several pairwise nonequivalent patterns.A International Blackbox Machine Corporation manufactures black boxes for various dictionaries, and claims that they ask the least number of questions possible. Your task is to help to verify this claim. ## Input SpecificationThe input consists of several instances, the instances are separated by single empty lines. The first line of each instance contains integers ## Output SpecificationFor each input instance, output a single line containing a single integer ## Sample Input4 4 1 2 3 4 1 3 2 4 2 1 4 3 3 1 2 4 1 1 1 ## Output for Sample Input2 0
## Chocolate Eating
Alice and Bob play the following game: they start with several chocolate bars, consisting of ## Input SpecificationThe input consists of several instances; input of each instance consists of single line (whose length is at most 1000000 characters). This line contains a nonempty list of integers ## Output SpecificationFor each input instance, output a single line containing a single integer ## Sample Input3 2 1 ## Output for Sample Input3
## srebmuN desreveR gniddA
Reversed number is a number written in arabic numerals but the order of digits is reversed. The first digit becomes last and vice versa. For example, if the original number is 1245, the reversed one becomes 5421. Note that all the leading zeros are omitted. That means if the number ends with a zero, the zero is lost by reversing (e.g. 1200, gives 21). Also note that the reversed number never has any trailing zeros. We need to calculate with reversed numbers. Your task is to add two reversed numbers and output their reversed sum. Of course, the result is not unique, because any particular number is a reversed form of several numbers (e.g., 21 could be 12, 120 or 1200 before reversing). Thus, we must assume that no zeros were lost by reversing (e.g., assume that the original number was 12). ## Input SpecificationThe input consists of ## Output SpecificationFor each case, print exactly one line containing only one integer - the reversed sum of two reversed numbers. Omit any leading zeros in the output. ## Sample Input3 24 1 4358 754 305 794 ## Output for Sample Input34 1998 1 ## Extra Safety
We want to build a bridge. A bridge is built by adding Given plans for a new bridge, you are to quickly verify that the bridge is safe. ## Input SpecificationThe input consists of several instances, separated by single empty lines. The first line of each instance consists of a single number ## Output SpecificationFor each input instance, output a single line containing one integer: the number of the first joint whose base is not solid. In other words, you are to find the first joint that, in the moment when it is being added, is connected to at least two previous joints that are not connected together. If there is no such joint, output the sentence "The bridge is safe." instead. ## Sample Input3 1 1 2 1 2 5 1 1 1 1 2 2 3 1 1 ## Output for Sample InputThe bridge is safe. 4
## Numbers Factorization
Factoring numbers into a product of primes is one of the most famous problems in mathematics. Your task is to solve this problem once for all. Remember that a ## Input SpecificationThe input consists of several lines, each of them containing one positive integer number, no bigger than 1000000. The last line contains the number zero, which signals the end of the input. ## Output SpecificationFor each of the positive numbers, print the number, one space, an equal sign (" The position of exponents must be exact, each of them beginning one character after the corresponding prime number. The main line (the one with primes) must be filled with extra spaces wherever an exponent appears. Do not display exponents that are equal to 1. If there are no exponents at all, you If the input number is a prime, print it, one space, and the phrase " Print one empty line after each factorization or phrase. There may be additional spaces at the end of any line. ## Sample Input144 13 10 1 65535 999808 0 ## Output for Sample Input4 2 144 = 2 x 3 13 is a prime number 10 = 2 x 5 1 is just a one 65535 = 3 x 5 x 17 x 257 7 999808 = 2 x 73 x 107
## Random Generators
A ## Input SpecificationThe input consists of several instances; input of each instance consists of a single line. This line contains four numbers ## Output SpecificationFor each input instance, output a single line containing two integers ## Sample Input5 5 10 10 5 6 6 7 ## Output for Sample Input15 15 0 3 ## Ball Lightning -- Help with the Moving
This time, we need you to help us with moving our offices. Currently, we live in ## Input SpecificationThe input consists of several instances; input of each instance consists of single line. This line contains an integer ## Output SpecificationFor each input instance, output a single line containing one integer - the number of days necessary to move all the persons, including the one day for the second phase. ## Sample Input5 1 2 3 5 4 ## Output for Sample Input4
## Intercal
Your task is to write one essential part of the Intercal compiler (Intercal is a well-known programming language). Your program should write in an integer from input, calculate its unary and, and read out the result. An ## Input SpecificationThe input consists of several instances; input of each instance consists of a single line. Each line contains one integer number A number between 21 and 99 whose number of units is not equal to zero is expressed as composition of terms for the tens and the units, e.g., 56 is "fifty six". A number between 100 and 999 is expressed by the term for hundreds, followed by "hundred", followed by the term for the remainder of the number modulo 100 if it is not zero, preceded by "and", e.g., 124 is "one hundred and twenty four" and 500 is "five hundred". A similar construction is used for multiples of 1000 (using word "thousand") and 1000000 (using word "million"). In these cases, the possible remainder of the number is not preceded by "and", e.g., 999999999 is "nine hundred and ninety nine million nine hundred and ninety nine thousand nine hundred and ninety nine" and 500000905 is "five hundred million nine hundred and five". ## Output SpecificationFor each input instance, output a single line containing the unary and of the input number. The number should be output in Roman numerals. It is guaranteed that the output will never be zero, nor greater than 3999. Roman numerals are represented by a string consisting of characters "I", "V", "X", "L", "C", "D" and "M". These symbols represent the decimal values 1, 5, 10, 50, 100, 500 and 1000 respectively. To represent other values, these symbols, and multiples where necessary, are concatenated, with the smaller-valued symbols written further to the right. For example, the number 3 is represented as "III", and the value 73 is represented as "LXXIII". The exceptions to this rule occur for numbers having units values of 4 or 9, tens values of 40 or 90, and hundreds values of 400 and 900. For these cases, the Roman numeral representations are "IV" (4), "IX" (9), "XL" (40), "XC" (90), "CD" (400) and "CM" (900). So the Roman numeral representations for 24, 39, 44, 49, and 94 are "XXIV", "XXXIX", "XLIV", "XLIX", and "XCIV", respectively. At most three consecutive characters "I", "X", "C" and "M" may appear in the numeral, and each numeral contains characters "V", "L", "D" at most once. It is forbidden to use e.g. "IC" for 99. ## Sample Inputthirteen ninety nine million ninety nine thousand nine hundred and ninety nine ## Output for Sample InputII MMLI |