문제
Rank teams from match records. Each record has the form First;Second;result, with no extra spaces. Result is win, loss, or draw from First’s perspective. A win earns 3 points, a draw earns 1 per team, and a loss earns 0. Count matches played, wins, draws, losses, and points for each team that appears. Sort by descending points, then ascending team name (ASCII order).
Return one semicolon-separated row per team: Name;Played;Won;Drawn;Lost;Points. Do not include a header or alignment spaces.
Implement tournament_standings(matches).
Input
matches: Match records, in any order.
Output
Return ranked rows with the six fields described above. Write numbers without leading zeros.
제약 조건
0…10,000 valid records. Team names contain 1…30 ASCII letters and are case-sensitive. Each match has two different names. Repeated matches are separate games. Empty input gives an empty result.
예시
입력:
matches = ["Falcons;Bears;win", "Bears;Owls;draw"]
예상 출력:
expected = ["Falcons;1;1;0;0;3", "Bears;2;0;1;1;1", "Owls;1;0;1;0;1"]
입력:
std::vector<std::string> matches = {"Falcons;Bears;win", "Bears;Owls;draw"};
예상 출력:
std::vector<std::string> expected = {"Falcons;1;1;0;0;3", "Bears;2;0;1;1;1", "Owls;1;0;1;0;1"};
입력:
string[] matches = new string[] {"Falcons;Bears;win", "Bears;Owls;draw"};
예상 출력:
string[] expected = new string[] {"Falcons;1;1;0;0;3", "Bears;2;0;1;1;1", "Owls;1;0;1;0;1"};
설명
Falcons have 3 points from their win. Bears and Owls each have 1 point from the draw, so Bears come first alphabetically. Bears played twice and lost once.
입력:
matches = ["Zebras;Ants;loss"]
예상 출력:
expected = ["Ants;1;1;0;0;3", "Zebras;1;0;0;1;0"]
입력:
std::vector<std::string> matches = {"Zebras;Ants;loss"};
예상 출력:
std::vector<std::string> expected = {"Ants;1;1;0;0;3", "Zebras;1;0;0;1;0"};
입력:
string[] matches = new string[] {"Zebras;Ants;loss"};
예상 출력:
string[] expected = new string[] {"Ants;1;1;0;0;3", "Zebras;1;0;0;1;0"};
설명
Loss is from Zebras’ perspective: Ants won and receive 3 points. Zebras receive 0.
접근 방법
먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.
힌트 1
경기 목록에 나온 모든 팀의 통계를 누적하세요. 한 번만 져도 포함해야 합니다.
힌트 2
각 기록은 두 팀을 동시에 갱신하며, 결과는 항상 첫 번째 팀 기준입니다.
힌트 3
합계를 모은 뒤에는 점수 내림차순, 팀 이름 오름차순으로 정렬하세요.
예상 복잡도
시간 O(m log t), 추가 공간 O(t)
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.