Felix Halim .NET  

Problem Statement

An election has just occurred. Given a int[] votes, where votes[i] is the number of votes for the ith candidate, you want to find the percentage of the total number of votes received by each candidate. If the percentage is not an integer, it must be rounded to an integer; you can choose to round up or down. You must make your choices in such a way that the sum of the percentages is exactly 100. Return the number of percentages for which you round up.


Class:              GeneralElection
Method:             numberOfRoundedUp
Parameters:         int[]
Returns:            int
Method signature:   int numberOfRoundedUp(int[] votes)
(be sure your method is public)


  • votes will contain between 1 and 50 elements, inclusive.
  • Each element of votes will be between 1 and 1000, inclusive.



{253, 253, 253, 241}
Returns: 1
The percentages are {25.3, 25.3, 25.3, 24.1}. If we round all the percentages down, the sum will be equal to 25 + 25 + 25 + 24 = 99. Therefore, one of the percentages must be rounded up.

{2, 3}
Returns: 0
The raw percentages are 40.0 and 60.0. They are already integers.

{500, 500}
Returns: 0
The raw percentages are 50.0 and 50.0. They are already integers.

Returns: 2


Returns: 0


Returns: 5

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

Google India Code Jam 2006 - Table of Contents

  1. Main Page - Google India Code Jam 2006
  2. Qualification Round
  3. Elimination Round
  4. Championship Round
  5. Links/Blogs/News

© Felix Halim 2009 (Loaded in 0.04451 secs)