Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleApp87
- {
- class Student
- {
- public Student(string courseName, int totalScore, Dictionary<string, int> allCourses)
- {
- this.CourseName = courseName;
- this.TotalScore = totalScore;
- this.AllCourses = allCourses;
- }
- public string CourseName { get; set; }
- public int TotalScore { get; set; }
- public Dictionary<string,int> AllCourses { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- var dict = new Dictionary<string, Student>();
- var coursesAndPass = new Dictionary<string, string>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "end of contests")
- {
- break;
- }
- string[] tokens = input.Split(':');
- if (!coursesAndPass.ContainsKey(tokens[0]))
- {
- coursesAndPass[tokens[0]] = tokens[1];
- }
- }
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "end of submissions")
- {
- break;
- }
- string[] tokens = input.Split("=>");
- int score = int.Parse(tokens[3]);
- if (coursesAndPass.ContainsKey(tokens[0]))
- {
- if (coursesAndPass[tokens[0]] == tokens[1])
- {
- if (!dict.ContainsKey(tokens[2]))
- {
- dict[tokens[2]] = new Student(tokens[0], score, new Dictionary<string, int>());
- dict[tokens[2]].AllCourses[tokens[0]] = score;
- }
- else
- {
- if (!dict[tokens[2]].AllCourses.ContainsKey(tokens[0]))
- {
- dict[tokens[2]].AllCourses[tokens[0]] = score;
- dict[tokens[2]].TotalScore += score;
- }
- else
- {
- if (dict[tokens[2]].AllCourses[tokens[0]] < score)
- {
- int diff = score - dict[tokens[2]].AllCourses[tokens[0]];
- dict[tokens[2]].AllCourses[tokens[0]] = score;
- dict[tokens[2]].TotalScore += diff;
- }
- }
- }
- }
- }
- }
- foreach (var item in dict.OrderByDescending(x => x.Value.TotalScore))
- {
- Console.WriteLine($"Best candidate is {item.Key} with total {item.Value.TotalScore} points.");
- break;
- }
- Console.WriteLine("Ranking:");
- foreach (var student in dict.OrderBy(x => x.Key))
- {
- Console.WriteLine($"{student.Key}");
- foreach (var kvp in student.Value.AllCourses.OrderByDescending(x => x.Value))
- {
- Console.WriteLine($"# {kvp.Key} -> {kvp.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement