ContestScore
SRM 154 · 2003-07-09 · by Karshikinpa
SRM 154 · 2003-07-09 · by Karshikinpa · Sorting, String Parsing
Problem Statement
Problem Statement
Some competitions have judges who score one specific area of a performance. Unfortunately, bad judges do exist and can individually cause one group's rating to be affected drastically. In some sports, the highest and lowest scores are dropped. This works well when all judges are scoring the same thing. However, when each judge scores only one aspect of a performance, dropping a score is not an option.
One way to minimize the effects of a bad judge is to not use the score each judge gives, but to use the relative ranking the judge gives each group. The group that places first has a ranking of 1. The group that places second has a ranking of 2, third has a ranking of 3, and so forth. When multiple groups are given the same score from one judge, then they will all receive the same ranking. For example, if the groups A, B, C, D, and E receive the scores 98, 95, 95, 90, and 83 respectively, then they would receive rankings of 1, 2, 2, 4, and 5, respectively.
Each group's rankings from all of the judges are then added together to find the group's total ranking. The group with the lowest total ranking places first. The group with the second lowest total ranking places second and so forth. Ties are broken using the sum of all scores the group receives from the judges to find the group's total score. The group with the highest total score wins the tiebreaker. If multiple groups have the same total ranking and the same total score, then the group whose name comes first alphabetically wins.
Create a class ContestScore with a method sortResults that is given aString[] data and will return a String[] containing the group names and scores sorted from first to last place. Every String in data will be formatted as: ("<GROUPNAME> NN.N NN.N NN.N") (quotes for clarity) where <GROUPNAME> will be between 1 and 10 characters in length, inclusive, and NN.N is a decimal number. It will have leading zeros if necessary to follow the above format. Each String in the returned String[] will be formatted as "<GROUPNAME> <TOTALRANK> <TOTALSCORE>" (quotes for clarity) where <TOTALRANK> is the group's total ranking and is an integer. <TOTALSCORE> is the sum of the scores received from all judges and will always have exactly one decimal place and no extra leading 0's. For example, if a group's <TOTALRANK> is 7 and <TOTALSCORE> is 271, then the string would be "<GROUPNAME> 7 271.0" (quotes for clarity).
For example, we have three groups. Group A scored a 90.7, a 92.9, and an 87.4. Group B scored a 90.5, a 96.6, and an 88.0. Group C scored a 92.2, a 91.0, and a 95.3. Here is how you would receive the data (quotes for clarity).
One way to minimize the effects of a bad judge is to not use the score each judge gives, but to use the relative ranking the judge gives each group. The group that places first has a ranking of 1. The group that places second has a ranking of 2, third has a ranking of 3, and so forth. When multiple groups are given the same score from one judge, then they will all receive the same ranking. For example, if the groups A, B, C, D, and E receive the scores 98, 95, 95, 90, and 83 respectively, then they would receive rankings of 1, 2, 2, 4, and 5, respectively.
Each group's rankings from all of the judges are then added together to find the group's total ranking. The group with the lowest total ranking places first. The group with the second lowest total ranking places second and so forth. Ties are broken using the sum of all scores the group receives from the judges to find the group's total score. The group with the highest total score wins the tiebreaker. If multiple groups have the same total ranking and the same total score, then the group whose name comes first alphabetically wins.
Create a class ContestScore with a method sortResults that is given a
For example, we have three groups. Group A scored a 90.7, a 92.9, and an 87.4. Group B scored a 90.5, a 96.6, and an 88.0. Group C scored a 92.2, a 91.0, and a 95.3. Here is how you would receive the data (quotes for clarity).
{"A 90.7 92.9 87.4",
"B 90.5 96.6 88.0",
"C 92.2 91.0 95.3"}
From judge 1, group C got 1st, group A got 2nd, and group B got 3rd. From judge 2, group B got 1st, group A got 2nd, and group C got 3rd. From judge 3, group C got 1st, group B got 2nd, and group A got 3rd.
A 2 2 3 B 3 1 2 C 1 3 1So A has a total ranking of 7, B has a total ranking of 6, and C has a total ranking of 5. Since C has the lowest total ranking, they place first. B places second, and A places third. You would return:
{"C 5 278.5",
"B 6 275.1",
"A 7 271.0"}Notes
- It is possible for a group to receive 00.0 for a score. Remember that leading and trailing zeros will be present if necessary in order to maintain formatting.
- Remember that if a group's total score is an exact integer to display it with one decimal place. Also, if the total score is between 0.0 and 0.9, inclusive, display one zero to the left of the decimal point. The last example shows this.
Constraints
- data will contain between 0 and 50 elements, inclusive.
- Each element of data will contain the exact same number of scores.
- Each element of data will contain between 6 and 50 characters, inclusive.
- There will be at least one judge.
- Each element of data will be formatted as a group name followed by a single space, followed by a single space delimited list of scores.
- Group names will be between 1 and 10 characters in length, and will consist of only of uppercase letters ('A'-'Z').
- No two groups will have the same name.
- The score from each judge will be formatted as NN.N where N is a digit ('0'-'9').
- There will be no leading or trailing spaces in each String of data.
Examples
0)
{"A 90.7 92.9 87.4",
"B 90.5 96.6 88.0",
"C 92.2 91.0 95.3"}
Returns: { "C 5 278.5", "B 6 275.1", "A 7 271.0" }
Example from above.
1)
{"STANFORD 85.3 90.1 82.6 84.6 96.6 94.5 87.3 90.3",
"MIT 95.5 83.9 80.4 85.5 98.7 98.3 96.7 82.7",
"PRINCETON 99.2 79.1 87.6 85.1 93.6 96.4 86.0 90.6",
"HARVARD 83.6 92.0 85.5 94.3 97.5 91.5 92.5 83.0",
"YALE 99.5 92.6 86.2 82.0 96.4 92.6 84.5 78.6",
"COLUMBIA 97.2 87.6 81.7 93.7 88.0 86.3 95.9 89.6",
"BROWN 92.2 95.8 92.1 81.5 89.5 87.0 95.5 86.4",
"PENN 96.3 80.7 81.2 91.6 85.8 92.2 83.9 87.8",
"CORNELL 88.0 83.7 85.0 83.8 99.8 92.1 91.0 88.9"}
Returns: { "PRINCETON 34 717.6", "MIT 36 721.7", "HARVARD 38 719.9", "COLUMBIA 39 720.0", "STANFORD 39 711.3", "YALE 40 712.4", "BROWN 41 720.0", "CORNELL 42 712.3", "PENN 51 699.5" }
2)
{}
Returns: { }
3)
{"ABCDE 99.9 99.9 99.9 99.9 99.9 99.9 99.9 99.9 99.9"}
Returns: { "ABCDE 9 899.1" }
4)
{"CALTECH 84.1 97.1 75.7 86.5 76.1 80.4 96.6 82.8",
"STANFORD 75.5 83.6 90.0 78.7 79.7 77.5 75.6 85.5",
"PRINCETON 86.6 81.4 97.8 87.4 78.2 89.7 84.1 89.1",
"MIT 94.7 88.1 75.0 93.9 95.8 91.0 88.2 85.9",
"DUKE 88.0 87.1 75.2 97.8 94.2 97.5 97.3 82.6",
"CORNELL 75.6 84.2 79.9 98.2 91.8 99.9 88.7 77.5",
"ARKANSAS 96.5 98.0 94.8 91.4 78.6 84.2 90.5 90.6",
"BERKELEY 98.8 83.9 92.8 98.8 85.9 90.2 93.7 99.9",
"ILLINOIS 98.5 98.7 91.0 81.0 76.1 82.7 93.3 83.8",
"UCLA 90.2 93.3 94.6 92.0 82.7 80.5 79.0 89.8",
"MINNESOTA 82.7 91.3 97.6 85.5 80.2 85.6 82.5 75.9",
"WASHINGTON 99.3 81.5 94.8 99.7 90.5 81.3 80.8 96.8",
"BYU 84.9 92.2 89.3 93.1 83.0 85.9 94.4 83.0",
"NEBRASKA 80.8 95.4 76.7 87.5 99.8 92.7 97.6 98.4",
"CARNEGIEME 95.6 87.1 93.4 76.6 76.2 77.7 84.1 93.1",
"TEXASAANDM 90.0 95.3 77.0 94.9 85.5 82.0 90.7 93.5",
"DARTMOUTH 97.5 96.9 86.2 89.8 91.7 90.4 87.8 90.6",
"HARVARD 97.5 93.1 85.7 96.7 80.1 84.1 98.8 82.6",
"UCF 87.5 88.1 83.8 86.7 87.5 77.6 92.0 97.6",
"UVA 76.5 89.6 88.9 82.8 92.7 88.6 90.9 99.0",
"MICHIGAN 84.4 94.8 80.5 78.4 82.0 98.1 87.3 82.3",
"MARYLAND 80.5 98.5 93.6 91.6 83.7 79.1 88.0 93.8",
"RUTGERS 99.1 78.7 85.8 88.9 99.5 85.1 89.5 97.6",
"WPI 90.7 84.8 79.4 93.5 97.8 91.2 95.4 83.6",
"TEXAS 92.8 78.9 86.0 86.6 87.0 84.1 94.8 78.0",
"UTAH 91.3 86.9 75.1 87.4 88.7 80.5 79.5 84.1",
"GEORGIATEC 84.5 99.7 81.7 75.7 98.7 86.6 99.3 96.1",
"VIRGINIATE 85.2 81.0 92.3 76.4 86.2 96.5 97.3 96.2",
"UMR 88.4 80.3 82.7 84.4 84.3 98.9 94.4 83.4",
"NYU 92.6 76.6 78.8 90.6 94.0 90.4 97.8 92.6",
"MICHIGANST 89.7 75.0 78.6 93.1 94.4 79.9 87.3 98.6",
"UNT 75.3 76.6 96.5 76.1 96.3 98.5 97.1 91.4",
"IOWASTATE 90.7 83.3 81.7 90.6 95.3 79.3 78.8 92.0",
"PURDUE 94.0 78.3 86.1 90.2 78.8 91.7 87.6 94.0",
"UCSD 84.7 96.4 86.5 85.6 84.7 77.2 90.5 94.4",
"USC 95.2 92.2 81.4 75.4 93.1 86.2 83.6 88.1",
"RIT 98.1 81.3 81.5 87.5 82.6 79.8 84.4 82.0",
"UCSB 84.8 75.1 93.5 85.0 85.3 94.1 88.3 95.5",
"WISCONSIN 85.5 81.9 95.6 84.8 94.4 98.5 95.5 95.1",
"NORTHEASTE 90.8 77.5 95.1 99.5 77.3 99.6 94.3 83.9",
"FLORIDA 77.6 90.9 86.5 84.8 89.3 91.9 81.0 82.9",
"STONYBROOK 77.6 80.4 97.5 85.3 81.6 77.8 85.8 77.7",
"EWU 95.1 94.9 76.2 75.9 83.5 84.6 87.0 79.4",
"UCR 87.3 86.6 91.0 93.6 98.4 82.7 92.7 93.2",
"OHIOSTATE 86.4 94.5 78.3 83.6 85.0 85.2 83.2 94.9",
"UCONN 97.0 75.1 75.2 80.2 84.8 90.5 77.7 92.1",
"PENNSTATE 84.6 86.1 89.4 93.6 92.1 79.5 83.1 78.2",
"RPI 94.0 97.5 82.4 98.9 92.3 98.3 98.4 93.3",
"UCIRVINE 94.4 94.1 92.6 84.0 78.9 91.1 94.0 93.9",
"FSU 97.0 97.0 93.4 81.7 76.4 89.6 79.2 97.7"}
Returns: { "RPI 99 755.1", "BERKELEY 116 744.0", "NEBRASKA 141 728.9", "WISCONSIN 142 731.3", "DARTMOUTH 152 730.9", "WASHINGTON 153 724.7", "RUTGERS 157 724.2", "GEORGIATEC 160 722.3", "UCR 162 725.5", "ARKANSAS 162 724.6", "WPI 169 716.4", "UCIRVINE 171 723.0", "NORTHEASTE 171 718.0", "DUKE 172 719.7", "HARVARD 174 718.6", "MIT 178 712.6", "NYU 179 713.4", "VIRGINIATE 183 711.1", "FSU 187 712.0", "TEXASAANDM 189 708.9", "UVA 190 709.0", "UNT 190 707.8", "MARYLAND 196 708.8", "BYU 198 705.8", "ILLINOIS 200 705.1", "UCSB 203 701.6", "UCF 205 700.8", "PURDUE 208 700.7", "UCLA 212 702.1", "MICHIGANST 215 696.6", "CORNELL 215 695.8", "UCSD 216 700.0", "UMR 219 696.8", "USC 223 695.2", "PRINCETON 226 694.3", "TEXAS 229 688.2", "IOWASTATE 231 691.7", "OHIOSTATE 235 691.1", "FLORIDA 237 684.9", "PENNSTATE 243 686.6", "CARNEGIEME 246 683.8", "MICHIGAN 253 687.8", "MINNESOTA 253 681.3", "UTAH 258 673.5", "RIT 259 677.2", "CALTECH 260 679.3", "EWU 260 676.6", "UCONN 263 672.6", "STONYBROOK 287 663.7", "STANFORD 316 646.1" }
26)
{"A 00.1", "B 05.2", "C 29.0","D 00.0"}
Returns: { "C 1 29.0", "B 2 5.2", "A 3 0.1", "D 4 0.0" }
Remember that, for numbers between 0.0 and 0.9, inclusive, you must display a 0 before the decimal point. Do not display any extraneous leading zeros if a number is between 1.0 and 9.9, inclusive.
Submissions are judged against all 52 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class ContestScore with a public method vector<string> sortResults(vector<string> data) · 52 test cases · 2 s / 256 MB per case