Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SoftUni_Exam_Results
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> dicLanguageSubmissions =
- new Dictionary<string, int>();
- List<Student> studentsList = new List<Student>();
- while (true)
- {
- string strSubmission = Console.ReadLine();
- if (strSubmission == "exam finished")
- {
- // print the output
- IEnumerable<Student> studentsListResult =
- from element in studentsList
- where element.IsBanned == false
- orderby element.Points descending, element.Name ascending
- select element;
- Console.WriteLine("Results:");
- foreach (Student item in studentsListResult)
- {
- Console.WriteLine($"{item.Name} | {item.Points}");
- }
- IEnumerable<KeyValuePair<string, int>> dicLanguageSubmissionsResult =
- from element in dicLanguageSubmissions
- orderby element.Value descending, element.Key ascending
- select element;
- Console.WriteLine("Submissions:");
- foreach (KeyValuePair<string, int> item in dicLanguageSubmissionsResult)
- {
- Console.WriteLine($"{item.Key} - {item.Value}");
- }
- break;
- }
- string[] strSubmissionArray = strSubmission.Split('-');
- switch (strSubmissionArray[1])
- {
- case "banned":
- {
- Student studentExists = studentsList.FirstOrDefault(
- s => s.Name == strSubmissionArray[0]);
- if (studentExists != null)
- {
- // get the student and make his banned state true
- int intIndex = studentsList.IndexOf(studentExists);
- studentsList[intIndex].IsBanned = true;
- }
- break;
- }
- default:
- {
- Student clsStudent = new Student(strSubmissionArray);
- // check whether the student has previous submissions
- Student studentExists = studentsList.FirstOrDefault(
- s => s.Name == clsStudent.Name);
- if (studentExists != null)
- {
- // get the student and correct the points if needed
- int intIndex = studentsList.IndexOf(studentExists);
- if (studentsList[intIndex].Points < clsStudent.Points)
- {
- studentsList[intIndex].Points = clsStudent.Points;
- }
- }
- else
- {
- studentsList.Add(clsStudent); // student's first submission
- }
- // submissions count by language
- if (dicLanguageSubmissions.ContainsKey(clsStudent.Language))
- {
- dicLanguageSubmissions[clsStudent.Language]++;
- }
- else
- {
- dicLanguageSubmissions.Add(clsStudent.Language, 1);
- }
- }
- break;
- }
- }
- }
- }
- class Student
- {
- public Student() { }
- public Student(string[] strNameLanguagePoints)
- {
- this.Name = strNameLanguagePoints[0];
- this.Language = strNameLanguagePoints[1];
- this.Points = int.Parse(strNameLanguagePoints[2]);
- this.IsBanned = false;
- }
- public string Name { get; set; }
- public string Language { get; set; }
- public int Points { get; set; }
- public bool IsBanned { get; set; }
- public override string ToString()
- {
- return this.Name + " | " + this.Points;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement