Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.61 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. namespace ConsoleApp87
  7. {
  8.     class Student
  9.     {
  10.         public Student(string courseName, int totalScore, Dictionary<string, int> allCourses)
  11.         {
  12.             this.CourseName = courseName;
  13.             this.TotalScore = totalScore;
  14.             this.AllCourses = allCourses;
  15.         }
  16.         public string CourseName { get; set; }
  17.         public int TotalScore { get; set; }
  18.         public Dictionary<string,int> AllCourses { get; set; }
  19.     }
  20.  
  21.     class Program
  22.     {
  23.  
  24.         static void Main(string[] args)
  25.         {
  26.  
  27.             var dict = new Dictionary<string, Student>();
  28.             var coursesAndPass = new Dictionary<string, string>();
  29.  
  30.             while (true)
  31.             {
  32.                 string input = Console.ReadLine();
  33.                 if (input == "end of contests")
  34.                 {
  35.                     break;
  36.                 }
  37.                 string[] tokens = input.Split(':');
  38.                 if (!coursesAndPass.ContainsKey(tokens[0]))
  39.                 {
  40.                     coursesAndPass[tokens[0]] = tokens[1];
  41.                 }
  42.                
  43.  
  44.             }
  45.  
  46.             while (true)
  47.             {
  48.                 string input = Console.ReadLine();
  49.                 if (input == "end of submissions")
  50.                 {
  51.                     break;
  52.                 }
  53.                 string[] tokens = input.Split("=>");
  54.                 int score = int.Parse(tokens[3]);
  55.  
  56.                 if (coursesAndPass.ContainsKey(tokens[0]))
  57.                 {
  58.                     if (coursesAndPass[tokens[0]] == tokens[1])
  59.                     {
  60.                         if (!dict.ContainsKey(tokens[2]))
  61.                         {
  62.                             dict[tokens[2]] = new Student(tokens[0], score, new Dictionary<string, int>());
  63.                             dict[tokens[2]].AllCourses[tokens[0]] = score;
  64.                         }
  65.                         else
  66.                         {
  67.                             if (!dict[tokens[2]].AllCourses.ContainsKey(tokens[0]))                              
  68.                             {
  69.                                 dict[tokens[2]].AllCourses[tokens[0]] = score;
  70.                                 dict[tokens[2]].TotalScore += score;
  71.                             }
  72.                             else
  73.                             {                                
  74.                                 if (dict[tokens[2]].AllCourses[tokens[0]] < score)
  75.                                 {
  76.                                     int diff = score - dict[tokens[2]].AllCourses[tokens[0]];
  77.                                     dict[tokens[2]].AllCourses[tokens[0]] = score;
  78.                                     dict[tokens[2]].TotalScore += diff;
  79.                                 }
  80.                             }
  81.                         }
  82.                     }
  83.                 }
  84.  
  85.             }
  86.  
  87.             foreach (var item in dict.OrderByDescending(x => x.Value.TotalScore))
  88.             {
  89.                 Console.WriteLine($"Best candidate is {item.Key} with total {item.Value.TotalScore} points.");
  90.                 break;
  91.             }
  92.  
  93.             Console.WriteLine("Ranking:");
  94.             foreach (var student in dict.OrderBy(x => x.Key))
  95.             {
  96.                 Console.WriteLine($"{student.Key}");
  97.                 foreach (var kvp in student.Value.AllCourses.OrderByDescending(x => x.Value))
  98.                 {
  99.                     Console.WriteLine($"#  {kvp.Key} -> {kvp.Value}");
  100.                 }
  101.             }
  102.  
  103.         }
  104.     }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement