Advertisement
yanass

Ranking

Oct 8th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.99 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Ranking
  6. {
  7.     class Contests
  8.     {
  9.         public string ContestsList { get; set; }
  10.         public string Password { get; set; }
  11.     }
  12.  
  13.     class Student
  14.     {
  15.         public string Name { get; set; }
  16.         public Dictionary<string, int> Contest { get; set; }
  17.     }
  18.     class Program
  19.     {
  20.         static void Main()
  21.         {
  22.             List<Contests> contest = new List<Contests>();
  23.             List<Student> students = new List<Student>();
  24.  
  25.             while (true)
  26.             {
  27.                 string[] contestsEntry = Console.ReadLine().Split(':');
  28.  
  29.                 if (contestsEntry[0] == "end of contests")
  30.                 {
  31.                     break;
  32.                 }
  33.                 string examName = contestsEntry[0];
  34.                 string passwordExam = contestsEntry[1];
  35.  
  36.                 Contests exam = new Contests();
  37.                 exam.ContestsList = examName;
  38.                 exam.Password = passwordExam;
  39.                 contest.Add(exam);
  40.             }
  41.  
  42.             while (true)
  43.             {
  44.                 string[] input = Console.ReadLine().Split("=>");
  45.  
  46.                 if (input[0] == "end of submissions")
  47.                 {
  48.                     break;
  49.                 }
  50.  
  51.                 string examName = input[0];
  52.                 string passwordExam = input[1];
  53.                 string username = input[2];
  54.                 int points = int.Parse(input[3]);
  55.  
  56.                 Student user = new Student();
  57.  
  58.                 if (contest.Select(x => x.ContestsList).Contains(examName)
  59.                     && contest.Select(x => x.Password).Contains(passwordExam))
  60.                 {
  61.                     if (!user.Name.Contains(username))
  62.                     {
  63.                         user.Name = username;
  64.                         user.Contest = new Dictionary<string, int>();
  65.                         user.Contest[examName] = points;
  66.                         students.Add(user);
  67.                     }
  68.  
  69.                     else if (!user.Contest.ContainsKey(examName))
  70.                     {
  71.                         user.Contest = new Dictionary<string, int>();
  72.                         user.Contest[examName] = points;
  73.                     }
  74.  
  75.                     else if (user.Contest[examName] < points)
  76.                     {
  77.                         user.Contest[examName] = points;
  78.                     }
  79.                 }
  80.             }
  81.             string bestStudent = "";
  82.             int maxPoints = -1;
  83.  
  84.             foreach (var student in students)
  85.             {
  86.                 int pointsCurrentStudent = student.Contest.Sum(x => x.Value);
  87.                 if (maxPoints < pointsCurrentStudent)
  88.                 {
  89.                     bestStudent = student.Name;
  90.                     maxPoints = pointsCurrentStudent;
  91.                 }
  92.             }
  93.  
  94.             Console.WriteLine($"Best candidate is {bestStudent} with total {maxPoints} points.");
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement