TopCoder problem "SimpleCardGame" used in TCHS SRM 63 (Division I Level One)



Problem Statement

    

A round of Blackjack has ended and it's time to reveal the winner. Use the following two rules to determine the outcome of the round:

  1. If a player has more than 21 points, he loses.
  2. Of all the players who have 21 or fewer points, the ones with the maximum number of points are the winners.

You are given a int[] points, where points[i] is the number of points received by the i-th player. If there is exactly one winner, return the 0-based index of the winning player. Otherwise, return -1.

 

Definition

    
Class:SimpleCardGame
Method:whoIsTheWinner
Parameters:int[]
Returns:int
Method signature:int whoIsTheWinner(int[] points)
(be sure your method is public)
    
 

Constraints

-points will contain between 1 and 50 elements, inclusive.
-Each element of points will be between 1 and 35, inclusive.
 

Examples

0)
    
{1, 2}
Returns: 1
Both players have 21 or fewer points. Among them, player 1 has the maximum number of points.
1)
    
{1, 2, 3, 3, 2}
Returns: -1
Players 2 and 3 both have the maximum number of points, so we have 2 winners.
2)
    
{1, 22}
Returns: 0
Player 1 has more than 21 points, so the winner is player 0.
3)
    
{21, 20, 19}
Returns: 0
4)
    
{22, 23, 22}
Returns: -1
No winner here.
5)
    
{1, 2, 21, 3, 4, 21}
Returns: -1
6)
    
{31, 33, 4, 23, 3, 23, 12, 35, 17, 27, 14, 6}
Returns: 8

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=10207

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13532&pm=10207

Writer:

DStepanenko

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Problem categories:

Search, Simulation