Advertisement
Guest User

Softuni Exam July 1

a guest
Aug 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Globalization;
  4. using System.Collections.Generic;
  5.  
  6. namespace SoftUni_Exam
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string input = Console.ReadLine();
  13.  
  14. int count = 1;
  15.  
  16. Dictionary<string, int> namesAndScores = new Dictionary<string, int>();
  17. Dictionary<string, int> languageAndCount = new Dictionary<string, int>();
  18.  
  19. int score1 = 0;
  20.  
  21. while (input != "exam finished")
  22. {
  23. List<string> lines = input.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  24.  
  25. string name = lines[0];
  26.  
  27. string language = lines[1];
  28.  
  29.  
  30. if (lines[1] != "banned")
  31. {
  32. int score = int.Parse(lines[2]);
  33.  
  34.  
  35. if (!namesAndScores.ContainsKey(name))
  36. {
  37.  
  38. namesAndScores[name] = score;
  39. score1 = score;
  40.  
  41. // misho 90
  42.  
  43. if (!languageAndCount.ContainsKey(language))
  44. {
  45. languageAndCount[language] = count;
  46. }
  47. else
  48. {
  49. languageAndCount[language]++;
  50. }
  51.  
  52. }
  53. else
  54. {
  55.  
  56. if (score >= score1 && score != 0)
  57. {
  58. namesAndScores[name] = score;
  59. languageAndCount[language] += count;
  60. }
  61. else
  62. {
  63. namesAndScores[name] = score1;
  64. languageAndCount[language] += count;
  65. }
  66.  
  67. }
  68.  
  69. }
  70. else
  71. {
  72. name = lines[0];
  73. namesAndScores.Remove(name);
  74. }
  75.  
  76. input = Console.ReadLine();
  77. }
  78.  
  79. Console.WriteLine("Results:");
  80.  
  81. foreach (var kvp in namesAndScores.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  82. {
  83. Console.WriteLine($"{kvp.Key} | {kvp.Value}");
  84. }
  85.  
  86. Console.WriteLine("Submissions:");
  87.  
  88. foreach (var kvp in languageAndCount.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  89. {
  90. Console.WriteLine($"{kvp.Key} - {kvp.Value}");
  91. }
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement