Programming contests

50 Programming Exercise for Beginners

January 2, 2019, 12:00 AM – December 31, 2019, 12:00 AM

The Turtle and the Snail

The turtle and the snail are playing the following game: they stand at the two ends of a small clearing, facing each other. The midpoint of the imaginary straight line joining their positions is designated as the goal, and for a given signal, they begin to run towards that point.

Write a program that processes the data of such a race. The first line of the input contains a positive integer (n) that specifies the number of minutes that this noble competition lasted. Each of the next two lines contains n nonnegative integers. The numbers in a line are separated by exactly one space character. The first n numbers specify how many centimeters the turtle travelled each minute during the race, and the second n numbers give the same information for the snail. The race ends after n minutes, then one (or both) of them reaches the goal.

Your program should write in the first line of the standard output the total length of the race track in centimeters. In the second line, depending on which competitor has reached the midpoint, write the word „TURTLE”, „SNAIL”, or „DRAW”.

Sample Input 1

  1. 3
  2. 1 2 3
  3. 1 1 1
download as text file

Output for Sample Input 1

  1. 12
  2. TURTLE
download as text file

Sample Input 2

  1. 3
  2. 1 2 3
  3. 3 2 1
download as text file

Output for Sample Input 2

  1. 12
  2. DRAW
download as text file

Sample Input 3

  1. 3
  2. 1 1 1
  3. 1 2 3
download as text file

Output for Sample Input 3

  1. 12
  2. SNAIL
download as text file
Acknowledgement This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.
University of Debrecen; Faculty of Informatics; v. 09/30/2024