THE 13TH LATVIAN OLYMPIAD IN INFORMATICS
2ND STAGE PROBLEMS 

Junior (7th-9th class) Group

1.“Letter Cubes”

    Rota has cubes with letters. On each cube one latin alphabet capital letter is written. More than one cube may have the same letter written on it. Rota has made a word by putting her cubes in a row. Rota's friend Zigmar would also like to put a word together, but he does not have any cubes. Rota agrees to lend only those cubes that are present in her word, and no other.

    Write a program that for the input words by Rota and Zigmar determines, whether Zigmar can put his imagined word together.

Input data
    The first line of the BURTI.DAT text file contains a string of symbole - Rota's word. The second line of the file contains also a string - Zigmar's imagined word. Each string contains only capital letters of the latin alphabet. Each string is at least one and at most 250 symbols long.

Output data
   The first line of the text file BURTI.REZ must contain the word VAR if Zigmar can put his imagined word together or the word NEVAR if this is not possible.

Examples
Input data (BURTI.DAT)             Output data (BURTI.REZ)
ALEKSANDRS                         VAR
SANDRA

Input data (BURTI.DAT)             Output data (BURTI.REZ)
SALMS                                      NEVAR
MALAS



  2.“Nearest Number”
    For a given positive integer n and digit c find the minimum possible positive integer k, for which both the following properties simultaneously apply:
1)k>n
2)the writing of k contains the digit c.

  Input data
    In the first line of the text file SKAITLIS.DAT the positive integer n and digit c are given, separated by a space symbol. It is known that 0<n<32750.

  Output data
    The first line of the text file SKAITLIS.REZ must contain the number k.

  Examples
Input data (SKAITLIS.DAT)         Output data (SKAITLIS.REZ)
11 7                                             17

Input data (SKAITLIS.DAT)         Output data (SKAITLIS.REZ)
19992 2                                       20000



3.“Pounds, shillings, and pence”
      A country had recently the following currency units: pounds, shillings, and pencei. These units were connected as follows: 1 pound = 20 shillings, 1 shilling = 12 pence. As this system was hard to convert to the currencies of other countries, it was decided to change to a new system, where only pounds and pence would exist (let us call these new pounds and new pence), which would be connected as follows:1 new pound = 100 new pencei. It was determined that the penny must not change its value (1 new penny = 1 penny). Write a program that for a given amount of money in the old system determines the corresponding amount in the new system.

Input data
The first line of the file NAUDA.DAT contains three non-negative integers n1, n2, and n3, which correspond to pound, shillings, and pence in the old currency system. It is known that the total value of the money does not exceed 100 "old" pounds. Each two numbers have a space symbol between them.

Output data
The first line of the file NAUDA.REZ must contain the input money in the new currency system as two non-negative integers - the amount of new pounds and new pence. The numbers must be separated by a space symbol. The sum must be converted, so that the number of new pence must be between 0 and 99.

Example
Input data (NAUDA.DAT)     Output data (NAUDA.REZ)
3 100 1000                           29 20

Input data (NAUDA.DAT)    Output data (NAUDA.REZ)
0 0 24000                             240 0


Senior (10th-12th class) Group

1.“Rectangle crossing”
 

One day Andris invented a game. To begin it, he first drew two parallel vertical and two horizontal segments, thus creating a rectangle as shown in the picture.

    Then he started to draw next segments, thus separating the starting rectangle to smaller rectangles. First, he drew a vertical segment exactly between the two vertical segments, then a horizontal segment between the two horizontal segments. The following segments Andris drew, first drawing all the vertical segments exactly half way between the already drawn vertical segments, then horizontal segments exactly half way between two horizontal segments. All the segments were long enough to intersect all the segments drawn in the other direction.
    Thus Andris continued to draw segments of a line, until exactly n segments were drawn.
   Write a program that for a given n deteremines, in how many rectangles the starting rectangle will have been divided!

Input data
   The first line of the text file TAISNST.DAT contains the natural number n - the total number of segments drawn (0<n<=90000).

Output data
   The first line of the text file TAISNST.REZ must contain one natural number - the number of the small rectangles the starting rectangle will have been divided to.
 

Example
Input data (TAISNST.DAT)

Output data (TAISNST.REZ) 
28

Note: The number besides a segment shows which it was in the order of drawing. 

2.“Well Ordered Numbers”

Let us call a well ordered an n-digit non-negative integer a = anan-1...a2a1, for the digits of which the following law applies: an >=an-1>=...>=a2 >=a1 Determine for a given n how many well ordered numbers exist.

Input data
The first line of the text file LABI.DAT must contain the value of the non-negative integer n (0<n<41).

Output data
The first line of the text file LABI.REZ must contain one natural number - the number of n-digit long well ordered numbers.

Example
Input data (fails LABI.DAT)    Output data ( fails LABI.REZ)
2                                            54

Note: These numbers are: 10,11,20,21,22,30,31,32,33,40,41,42,43,44, 50,51,52,53,54,55,60,61,62,63,64,65,66,70,71,72,73,74,75,76, 77,80,81,82,83,84,85,86,87,88,90,91,92,93,94,95,96,97,98,99.


3.“An Encrypted Message for James Bond”
 

The famous agent 007 (James Bond) had a characteristic feature never expressed in literature. If he received an encrypted message containing a digit-only string, containing a square of any natural number n (1<n<=10000), he became nervous, which in turn for some time significantly lowered his ability to work. To avoid this effect, Mr.X suggested acting as follows to find the square of a natural number n2 (where n is a natural number as specified above) that starts leftmost in the encrypted message entitled for James Bond and replace it with the number n. If more than one square of an integer starts at the given position, then replace the shortest of them. A square of a number does not start with 0. Then repeat the action with the new encrypted message until there are no more squares of integer numbers in the given range in the remainder of the message.

Your task is to write a computer program that would apply Mr.X's suggested algorithm.

Input data
    The first line of the input file BONDS.DAT contains a digit-only string without any separators – the starting content of the encrypted message. It is known that the string contains no less than 1 and no more than 250 digits. The first digit of the string is not 0.

Output data
    The output file BONDS.REZ must contain only one line, and it has to be the a string – the text of the modified encrypted message.

Examples
Input data (BONDS.DAT)    Output data (BONDS.REZ)
734424                                268

Note: Modification was done thus: 734424 -> 732424 -> 71824 -> 268

Input data (BONDS.DAT)    Output data (BONDS.REZ)
8136045                              605 


Home