Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _01.Ranking
- {
- class Program
- {
- private class Student
- {
- public string Name { get; }
- public Dictionary<string, int> ContestWithPoints { get; }
- public Student(string name)
- {
- Name = name;
- ContestWithPoints = new Dictionary<string, int>();
- }
- }
- static void Main(string[] args)
- {
- Dictionary<string, string> contests = new Dictionary<string, string>();
- Dictionary<string, Student> userPoints = new Dictionary<string, Student>();
- string line;
- while ((line = Console.ReadLine()) != "end of contests")
- {
- string[] parts = line.Split(":", StringSplitOptions.RemoveEmptyEntries);
- string contest = parts[0];
- string password = parts[1];
- if (!contests.ContainsKey(contest))
- {
- contests.Add(contest, password);
- }
- }
- while ((line = Console.ReadLine()) != "end of submissions")
- {
- string[] parts = line.Split("=>", StringSplitOptions.RemoveEmptyEntries);
- string contest = parts[0];
- string password = parts[1];
- string username = parts[2];
- int points = int.Parse(parts[3]);
- if (!contests.ContainsKey(contest) || contests[contest] != password)
- {
- continue;
- }
- if (!userPoints.ContainsKey(username))
- {
- userPoints.Add(username, new Student(username));
- }
- Student student = userPoints[username];
- if (!student.ContestWithPoints.ContainsKey(contest))
- {
- student.ContestWithPoints.Add(contest, points);
- }
- if (student.ContestWithPoints[contest] < points)
- {
- student.ContestWithPoints[contest] = points;
- }
- }
- PrintTheRanking(userPoints.Values.ToList());
- }
- private static void PrintTheRanking(List<Student> listWithStudents)
- {
- var bestCandidate = listWithStudents
- .OrderByDescending(x => x.ContestWithPoints.Values.Sum())
- .First();
- Console.WriteLine($"Best candidate is {bestCandidate.Name} with total {bestCandidate.ContestWithPoints.Values.Sum()} points.");
- Console.WriteLine("Ranking:");
- foreach (var student in listWithStudents.OrderBy(x => x.Name))
- {
- Console.WriteLine(student.Name);
- foreach (var (contest, points) in student.ContestWithPoints.OrderByDescending(x => x.Value))
- {
- Console.WriteLine($"# {contest} -> {points}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement