Advertisement
KAMEN1973

Untitled

Mar 16th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace SoftUni_Exam_Results
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Dictionary<string, int> dicLanguageSubmissions =
  14. new Dictionary<string, int>();
  15. List<Student> studentsList = new List<Student>();
  16.  
  17. while (true)
  18. {
  19. string strSubmission = Console.ReadLine();
  20. if (strSubmission == "exam finished")
  21. {
  22. // print the output
  23. IEnumerable<Student> studentsListResult =
  24. from element in studentsList
  25. where element.IsBanned == false
  26. orderby element.Points descending, element.Name ascending
  27. select element;
  28. Console.WriteLine("Results:");
  29. foreach (Student item in studentsListResult)
  30. {
  31. Console.WriteLine($"{item.Name} | {item.Points}");
  32. }
  33.  
  34. IEnumerable<KeyValuePair<string, int>> dicLanguageSubmissionsResult =
  35. from element in dicLanguageSubmissions
  36. orderby element.Value descending, element.Key ascending
  37. select element;
  38. Console.WriteLine("Submissions:");
  39. foreach (KeyValuePair<string, int> item in dicLanguageSubmissionsResult)
  40. {
  41. Console.WriteLine($"{item.Key} - {item.Value}");
  42. }
  43. break;
  44. }
  45.  
  46. string[] strSubmissionArray = strSubmission.Split('-');
  47.  
  48. switch (strSubmissionArray[1])
  49. {
  50. case "banned":
  51. {
  52. Student studentExists = studentsList.FirstOrDefault(
  53. s => s.Name == strSubmissionArray[0]);
  54. if (studentExists != null)
  55. {
  56. // get the student and make his banned state true
  57. int intIndex = studentsList.IndexOf(studentExists);
  58. studentsList[intIndex].IsBanned = true;
  59. }
  60. break;
  61. }
  62. default:
  63. {
  64. Student clsStudent = new Student(strSubmissionArray);
  65.  
  66. // check whether the student has previous submissions
  67. Student studentExists = studentsList.FirstOrDefault(
  68. s => s.Name == clsStudent.Name);
  69. if (studentExists != null)
  70. {
  71. // get the student and correct the points if needed
  72. int intIndex = studentsList.IndexOf(studentExists);
  73. if (studentsList[intIndex].Points < clsStudent.Points)
  74. {
  75. studentsList[intIndex].Points = clsStudent.Points;
  76. }
  77.  
  78. }
  79. else
  80. {
  81. studentsList.Add(clsStudent); // student's first submission
  82. }
  83.  
  84. // submissions count by language
  85. if (dicLanguageSubmissions.ContainsKey(clsStudent.Language))
  86. {
  87. dicLanguageSubmissions[clsStudent.Language]++;
  88. }
  89. else
  90. {
  91. dicLanguageSubmissions.Add(clsStudent.Language, 1);
  92. }
  93. }
  94. break;
  95. }
  96.  
  97.  
  98.  
  99. }
  100. }
  101. }
  102.  
  103. class Student
  104. {
  105. public Student() { }
  106. public Student(string[] strNameLanguagePoints)
  107. {
  108. this.Name = strNameLanguagePoints[0];
  109. this.Language = strNameLanguagePoints[1];
  110. this.Points = int.Parse(strNameLanguagePoints[2]);
  111. this.IsBanned = false;
  112. }
  113. public string Name { get; set; }
  114. public string Language { get; set; }
  115. public int Points { get; set; }
  116.  
  117. public bool IsBanned { get; set; }
  118.  
  119. public override string ToString()
  120. {
  121. return this.Name + " | " + this.Points;
  122. }
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement