Advertisement
Prohause

SoftUni Exam Results

Aug 20th, 2018
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Test
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, int> nameAndPoints = new Dictionary<string, int>();
  12. Dictionary<string, int> languageAndCount = new Dictionary<string, int>();
  13.  
  14. while (true)
  15. {
  16. string input = Console.ReadLine();
  17. if (input == "exam finished")
  18. {
  19. break;
  20. }
  21. string[] data = input.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
  22.  
  23. if (data.Length == 2) //когато има banned
  24. {
  25. string user = data[0];
  26. if (nameAndPoints.ContainsKey(user))
  27. {
  28. nameAndPoints.Remove(user);
  29. }
  30. }
  31. else
  32. {
  33. string user = data[0];
  34. string language = data[1];
  35. int points = int.Parse(data[2]);
  36.  
  37. if (!languageAndCount.ContainsKey(language))
  38. {
  39. languageAndCount.Add(language, 1);
  40. }
  41. else
  42. {
  43. languageAndCount[language]++;//obnovqvam (prebroqvam) stoinostta primerno ako ima tozi
  44. //ezik edin put stoinostta 6te stane 2
  45. }
  46.  
  47. if (nameAndPoints.ContainsKey(user))
  48. {
  49. if (points > nameAndPoints[user])
  50. {
  51. nameAndPoints[user] = points;
  52. }
  53. }
  54. else
  55. {
  56. nameAndPoints.Add(user, points);
  57. }
  58. }
  59. }
  60. Console.WriteLine("Results:");
  61. foreach (var item in nameAndPoints.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  62. {
  63.  
  64. Console.WriteLine($"{item.Key} | {item.Value}");
  65.  
  66. }
  67. Console.WriteLine("Submissions:");
  68. foreach (var item1 in languageAndCount.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  69. {
  70. Console.WriteLine($"{item1.Key} - {item1.Value}");
  71. }
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement