MedalTable
SRM 209 · 2004-08-28 · by Wernie
SRM 209 · 2004-08-28 · by Wernie · Sorting
Problem Statement
Problem Statement
The Olympic Games in Athens end tomorrow.
Given the results of the olympic disciplines, generate and return the medal table.
The results of the disciplines are given as aString[] results,
where each element is in the format "GGG SSS BBB". GGG, SSS and
BBB are the 3-letter country codes (three capital letters from 'A' to 'Z') of the countries winning
the gold, silver and bronze medal, respectively.
The medal table is aString[] with an element for each country appearing in results.
Each element has to be in the format "CCO G S B" (quotes for clarity), where
G, S and B are the number of gold, silver and bronze medals won
by country CCO, e.g. "AUT 1 4 1". The numbers should not have any extra leading zeros.
Sort the elements by the number of gold medals won in decreasing order. If several countries are tied, sort the tied countries by the number of silver medals won in decreasing order. If some countries are still tied, sort the tied countries by the number of bronze medals won in decreasing order. If a tie still remains, sort the tied countries by their 3-letter code in ascending alphabetical order.
The results of the disciplines are given as a
The medal table is a
Sort the elements by the number of gold medals won in decreasing order. If several countries are tied, sort the tied countries by the number of silver medals won in decreasing order. If some countries are still tied, sort the tied countries by the number of bronze medals won in decreasing order. If a tie still remains, sort the tied countries by their 3-letter code in ascending alphabetical order.
Constraints
- results contains between 1 and 50 elements, inclusive.
- Each element of results is formatted as described in the problem statement.
- No more than 50 different countries appear in results.
Examples
0)
{"ITA JPN AUS", "KOR TPE UKR", "KOR KOR GBR", "KOR CHN TPE"}
Returns: { "KOR 3 1 0", "ITA 1 0 0", "TPE 0 1 1", "CHN 0 1 0", "JPN 0 1 0", "AUS 0 0 1", "GBR 0 0 1", "UKR 0 0 1" }
These are the results of the archery competitions.
1)
{"USA AUT ROM"}
Returns: { "USA 1 0 0", "AUT 0 1 0", "ROM 0 0 1" }
2)
{"GER AUT SUI", "AUT SUI GER", "SUI GER AUT"}
Returns: { "AUT 1 1 1", "GER 1 1 1", "SUI 1 1 1" }
3)
{"SOL MOZ BOT", "JOR CUB GUA", "TPE MRI BLR", "KEN NRU KSA", "PAK BLR TPE", "MLT CZE BRA", "KAZ TLS NCA", "TLS ECU GBS", "NRU ECU TAN", "ANG PAR CAF", "KGZ KUW PLE", "NRU AZE ANT", "BEL YUG NCA", "CHA KGZ GRE", "PUR CUB KGZ", "PAK THA PUR", "TLS GUA NRU", "KUW GBS ANT", "UGA ARG GBS", "SRI ARG BOT", "ANT MOZ PAK", "SOL EST PUR", "THA GRN RSA", "MLT MRI GBS", "UGA GUY MRI", "KEN CGO KSA", "GBS BOT UGA", "AZE PAK EST", "BOT NGR GRN", "KAZ KUW GUY", "NCA MLT AZE"}
Returns: { "NRU 2 1 1", "PAK 2 1 1", "MLT 2 1 0", "TLS 2 1 0", "UGA 2 0 1", "KAZ 2 0 0", "KEN 2 0 0", "SOL 2 0 0", "KUW 1 2 0", "GBS 1 1 3", "BOT 1 1 2", "AZE 1 1 1", "KGZ 1 1 1", "THA 1 1 0", "ANT 1 0 2", "NCA 1 0 2", "PUR 1 0 2", "TPE 1 0 1", "ANG 1 0 0", "BEL 1 0 0", "CHA 1 0 0", "JOR 1 0 0", "SRI 1 0 0", "MRI 0 2 1", "ARG 0 2 0", "CUB 0 2 0", "ECU 0 2 0", "MOZ 0 2 0", "BLR 0 1 1", "EST 0 1 1", "GRN 0 1 1", "GUA 0 1 1", "GUY 0 1 1", "CGO 0 1 0", "CZE 0 1 0", "NGR 0 1 0", "PAR 0 1 0", "YUG 0 1 0", "KSA 0 0 2", "BRA 0 0 1", "CAF 0 0 1", "GRE 0 0 1", "PLE 0 0 1", "RSA 0 0 1", "TAN 0 0 1" }
4)
{"KEN JAM BAN", "SEN DEN DEN", "PAN BLR RSA", "BAN FRG KAZ", "PAN GAB FIJ", "FIJ TRI ISL", "SEN GAM MAD", "RSA ZIM HON", "ISV SMR RSA", "BAR PER BAN", "NED GAB LES", "SCG DMA UAE", "BRN BAR BAN", "VEN CHN HON", "KAZ ZIM SEN", "TRI FRG RSA", "HON CHN CHI", "BAR AHO CHN", "KSA KAZ BAR", "GAM NED SMR", "JAM HON ERI", "BUL EUN LES", "BUL ISL NZL", "CUB ISL AFG", "NED ARG ZIM", "KEN AFG FRG", "GEO HUN LCA", "LCA KSA MAD", "SMR CHI DEN", "ZIM LCA ZIM", "TRI BUR HUN", "DEN FRG RSA"}
Returns: { "BAR 2 1 1", "NED 2 1 0", "TRI 2 1 0", "SEN 2 0 1", "BUL 2 0 0", "KEN 2 0 0", "PAN 2 0 0", "ZIM 1 2 2", "DEN 1 1 2", "HON 1 1 2", "KAZ 1 1 1", "LCA 1 1 1", "SMR 1 1 1", "GAM 1 1 0", "JAM 1 1 0", "KSA 1 1 0", "RSA 1 0 4", "BAN 1 0 3", "FIJ 1 0 1", "BRN 1 0 0", "CUB 1 0 0", "GEO 1 0 0", "ISV 1 0 0", "SCG 1 0 0", "VEN 1 0 0", "FRG 0 3 1", "CHN 0 2 1", "ISL 0 2 1", "GAB 0 2 0", "AFG 0 1 1", "CHI 0 1 1", "HUN 0 1 1", "AHO 0 1 0", "ARG 0 1 0", "BLR 0 1 0", "BUR 0 1 0", "DMA 0 1 0", "EUN 0 1 0", "PER 0 1 0", "LES 0 0 2", "MAD 0 0 2", "ERI 0 0 1", "NZL 0 0 1", "UAE 0 0 1" }
Submissions are judged against all 36 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class MedalTable with a public method vector<string> generate(vector<string> results) · 36 test cases · 2 s / 256 MB per case