Programming contests

50 Programming Exercise for Beginners

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

E — Caesar

Little Caesar likes card games. Every time he comes to Zagreb, he plays blackjack, the famous card game, with his friends.

In this game, the player draws cards while the sum of the cards in his hand is less than or equal to 21 or until he says “STOP”.

At the beginning of the game, there are 52 cards in the deck, thirteen ranks of each of the four suits. The card ranks are two, three, …, ten, Jack, Queen, King, and Ace. The card values are the following: the cards with numbers on them are worth that number (e.g., “nine” is 9), the cards with pictures (Jack, Queen, and King) are worth 10, whereas Ace is worth 11.

Caesar has found himself in an interesting situation. During the game, he already drew N cards whose sum is less than or equal to 21 and is now pondering over drawing one more card or not. Let's assume X is the difference between 21 and the sum of the cards in his hand. Everybody knows that you don't draw a card if the number of the remaining cards in the deck whose value is greater than X is greater than or equal to the number of the remaining cards in the deck whose value is less than or equal to X.

Since Caesar is having a difficult time calculating whether he needs to draw another card or not, he's asking you to do it for him.

Input Specification

The first line of the input contains a positive integer N (1 ≤ N ≤ 52), the number of cards Caesar has drawn so far.

Each of the following N lines contains a single positive integer, the value of the ith card Caesar drew.

Output Specification

If Caesar should draw another card, output “DRAW”, otherwise output “STOP”.

Sample Input 1

  1. 6
  2. 2
  3. 3
  4. 2
  5. 3
  6. 2
  7. 3
download as text file

Output for Sample Input 1

  1. STOP
download as text file

Sample Input 2

  1. 1
  2. 10
download as text file

Output for Sample Input 2

  1. DRAW
download as text file

Sample Input 3

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

Output for Sample Input 3

  1. DRAW
download as text file

Clarification of Sample 1

The sum of the already drawn cards is 15, and the difference X to 21 is 6. The number of cards in the deck with a value greater than 6 is 32 (4 Aces, 4 Kings, 4 Queens, 4 Jacks, 4 tens, 4 nines, 4 eights, and 4 sevens), whereas the number of cards in the deck with a value less than or equal to 6 is 14 (one two, one three, 4 fours, 4 fives, and 4 sixes).

Original Problem

Croatian Open Competition in Informatics 2017/2018, Contest #1, Cezar

University of Debrecen; Faculty of Informatics; v. 09/30/2024