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.
The input file is structured as follows:
Example:
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:
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:
- The first line contains the number n of valid choices
- The following n lines each contain a choice
- The following line contains the number p of vote bags
- 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.75Important: 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 | ||||||
Unit Tests
| Name | CPU Unit | Memory Unit |
|---|---|---|
Small3 voting options, 105 bags |
||
Medium10 voting options, 835 bags |
||
Large25 voting options, 1489 bags |
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.