Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace Ranking
- {
- class Contests
- {
- public string ContestsList { get; set; }
- public string Password { get; set; }
- }
- class Student
- {
- public string Name { get; set; }
- public Dictionary<string, int> Contest { get; set; }
- }
- class Program
- {
- static void Main()
- {
- List<Contests> contest = new List<Contests>();
- List<Student> students = new List<Student>();
- while (true)
- {
- string[] contestsEntry = Console.ReadLine().Split(':');
- if (contestsEntry[0] == "end of contests")
- {
- break;
- }
- string examName = contestsEntry[0];
- string passwordExam = contestsEntry[1];
- Contests exam = new Contests();
- exam.ContestsList = examName;
- exam.Password = passwordExam;
- contest.Add(exam);
- }
- while (true)
- {
- string[] input = Console.ReadLine().Split("=>");
- if (input[0] == "end of submissions")
- {
- break;
- }
- string examName = input[0];
- string passwordExam = input[1];
- string username = input[2];
- int points = int.Parse(input[3]);
- Student user = new Student();
- if (contest.Select(x => x.ContestsList).Contains(examName)
- && contest.Select(x => x.Password).Contains(passwordExam))
- {
- if (!user.Name.Contains(username))
- {
- user.Name = username;
- user.Contest = new Dictionary<string, int>();
- user.Contest[examName] = points;
- students.Add(user);
- }
- else if (!user.Contest.ContainsKey(examName))
- {
- user.Contest = new Dictionary<string, int>();
- user.Contest[examName] = points;
- }
- else if (user.Contest[examName] < points)
- {
- user.Contest[examName] = points;
- }
- }
- }
- string bestStudent = "";
- int maxPoints = -1;
- foreach (var student in students)
- {
- int pointsCurrentStudent = student.Contest.Sum(x => x.Value);
- if (maxPoints < pointsCurrentStudent)
- {
- bestStudent = student.Name;
- maxPoints = pointsCurrentStudent;
- }
- }
- Console.WriteLine($"Best candidate is {bestStudent} with total {maxPoints} points.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement