Vote count

Description

Discuss (28 comments)
The purpose of this puzzle is to count the number of votes assigned to a given set of choices and to determine the winner (the choice with the most votes) and the percentage of votes it received.

If several options have the maximum number of votes they should be displayed in alphabetical order.

Input Specifications

Your program must take a single command line argument: the name of a file.
The input file is structured as follows:
  1. The first line contains the number n of valid choices
  2. The following n lines each contain a choice
  3. The following line contains the number p of vote bags
  4. The following p lines contain a bag definition choice count where:
    • choice is a choice, note that if the choice doesn't appear in the valid choices, it must be ignored
    • count is number of votes in that bag for that particular choice

Example:
3
Coffee
Chocolate
Tea
5
Coffee 10
Tea 35
Soup 7
Chocolate 10
Coffee 25

Output Specifications

The output result should printed on the standard output.
All valid options having the same maximum number of votes should be displayed in alphabetical order followed by the percentage of votes received.

For the previous example, the expected output is:
Coffee 43.75
Tea 43.75
Important: The output percentage must have exactly 2 fractional digits, e.g. it must be of the form *.ab where a,b are digits between 0 and 9.

Scoring

The score is proportional to the size of your program, every character counts (including spaces, newlines, etc...). The more compact your program, the higher your score. If your program uses more than 2000 chars, it will score 0 points.
© CoderCharts - All Rights Reserved
Type Puzzle Pass 781 Fail 329
Scoring Language Level Easy Points 100
Tags statistics

Source code editor

Unit Tests

Name CPU Unit Memory Unit

Small

3 voting options, 105 bags
1s
100 MB

Medium

10 voting options, 835 bags
1s
100 MB

Large

25 voting options, 1489 bags
1s
100 MB

Confirm that you want to switch languages
Your current edits will be lost.

Confirm that you wish to load a previous submission
Your current edits will be lost.