Advertisement
JulianJulianov

15.AsociativeArrays-*SoftUni Exam Results

Apr 12th, 2020
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.08 KB | None | 0 0
  1. 15. *SoftUni Exam Results
  2. Judge statistics on the last Programing Fundamentals exam was not working correctly, so you have the task to take all the submissions and analyze them properly. You should collect all the submissions and print the final results and statistics about each language that the participants submitted their solutions in.
  3. You will be receiving lines in the following format: "{username}-{language}-{points}" until you receive "exam finished". You should store each username and his submissions and points.
  4. You can receive a command to ban a user for cheating in the following format: "{username}-banned". In that case, you should remove the user from the contest, but preserve his submissions in the total count of submissions for each language.
  5. After receiving "exam finished" print each of the participants, ordered descending by their max points, then by username, in the following format:
  6. Results:
  7. {username} | {points}
  8. After that print each language, used in the exam, ordered descending by total submission count and then by language name, in the following format:
  9. Submissions:
  10. {language}{submissionsCount}
  11. Input / Constraints
  12. Until you receive "exam finished" you will be receiving participant submissions in the following format: "{username}-{language}-{points}".
  13. You can receive a ban command -> "{username}-banned"
  14. The points of the participant will always be a valid integer in the range [0-100];
  15. Output
  16. • Print the exam results for each participant, ordered descending by max points and then by username, in the following format:
  17. Results:
  18. {username} | {points}
  19. • After that print each language, ordered descending by total submissions and then by language name, in the following format:
  20. Submissions:
  21. {language}{submissionsCount}
  22. • Allowed working time / memory: 100ms / 16MB.
  23. Examples
  24. Input                         Output                          Comment
  25. Pesho-Java-84                 Results:                        We order the participant descending by max points and then by name,
  26. Gosho-C#-84                   Kiro | 94                       printing only the username and the max points.
  27. Gosho-C#-70                   Gosho | 84                      After that we print each language along with the count of submissions,
  28. Kiro-C#-94                    Pesho | 84                      ordered descending by submissions count, and then by language name.
  29. exam finished                 Submissions:
  30.                               C# - 3
  31.                               Java - 1
  32.  
  33. Pesho-Java-91                 Results:                        Kiro is banned so he is removed from the contest, but he`s submissions
  34. Gosho-C#-84                   Pesho | 91                      are still preserved in the languages submissions count.
  35. Kiro-Java-90                  Gosho | 84                      So althou there are only 2 participants in the results,
  36. Kiro-C#-50                    Submissions:                    there are 4 submissions in total.
  37. Kiro-banned                   C# - 2
  38. exam finished                 Java - 2
  39.  
  40.  
  41. using System;
  42. using System.Collections.Generic;
  43. using System.Linq;
  44.  
  45. namespace ExamResults
  46. {
  47.     class Program
  48.     {
  49.         static void Main(string[] args)
  50.         {
  51.             var points = new Dictionary<string, int>();
  52.             var submissions = new Dictionary<string, int>();
  53.  
  54.             while (true)
  55.             {
  56.                 var input = Console.ReadLine();
  57.  
  58.                 if (input == "exam finished")
  59.                 {
  60.                     break;
  61.                 }
  62.  
  63.                 var data = input.Split('-');
  64.  
  65.                 var name = data[0];
  66.  
  67.                 if (data[1] != "banned")
  68.                 {
  69.                     if (points.ContainsKey(name) == false)
  70.                     {
  71.                         points.Add(name, 0);
  72.                     }
  73.  
  74.                     var currentPoints = int.Parse(data[2]);
  75.  
  76.                     if (points[name] < currentPoints)
  77.                     {
  78.                         points[name] = currentPoints;
  79.                     }
  80.  
  81.                     var language = data[1];
  82.  
  83.                     if (submissions.ContainsKey(language) == false)
  84.                     {
  85.                         submissions.Add(language, 0);
  86.                     }
  87.  
  88.                     submissions[language]++;
  89.                 }
  90.                 else
  91.                 {
  92.                     if (points.ContainsKey(name))
  93.                     {
  94.                         points.Remove(name);
  95.                     }
  96.                 }
  97.             }
  98.  
  99.             Console.WriteLine("Results:");
  100.  
  101.             foreach (var participant in points.OrderByDescending(p => p.Value).ThenBy(p => p.Key))
  102.             {
  103.                 Console.WriteLine($"{participant.Key} | {participant.Value}");
  104.             }
  105.  
  106.             Console.WriteLine("Submissions:");
  107.  
  108.             foreach (var language in submissions.OrderByDescending(s => s.Value).ThenBy(s => s.Key))
  109.             {
  110.                 Console.WriteLine($"{language.Key} - {language.Value}");
  111.             }
  112.         }
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement