nassss

Untitled

Jan 28th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace StudentScoresDictionary
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<string> input = Console.ReadLine().Split(' ').ToList();
  12. var dict = new Dictionary<string, Dictionary<string, List<int>>>();
  13.  
  14. while (input[0] != "print" || (input[0] != "print" && dict.ContainsKey(input[1])))
  15. {
  16.  
  17. if (!dict.ContainsKey(input[1]))
  18. {
  19. dict.Add(input[1], new Dictionary<string, List<int>>());
  20.  
  21. }
  22. if (!dict[input[1]].ContainsKey(input[2]))
  23. {
  24. dict[input[1]].Add(input[2], new List<int>());
  25. }
  26. if (input.Count == 4)
  27. {
  28. dict[input[1]][input[2]].Add(int.Parse(input[3]));
  29. }
  30. input = Console.ReadLine().Split(' ').ToList();
  31.  
  32. }
  33. if (input.Count == 2 && input[0] == "print" && dict.ContainsKey(input[1]))
  34. {
  35. Console.WriteLine($"{input[1]}");
  36.  
  37. foreach (var subject in dict[input[1]])
  38. {
  39. Console.WriteLine($"- {subject.Key}: {String.Join(", ", subject.Value)}");
  40. }
  41. }
  42. else if (input[0] == "print" && input.Count == 1)
  43. {
  44. foreach (var student in dict)
  45. {
  46. Console.WriteLine($"{student.Key}");
  47.  
  48. foreach (var subject in dict[student.Key])
  49. {
  50. Console.WriteLine($"- {subject.Key}: {String.Join(", ", subject.Value)}");
  51. }
  52. }
  53. }
  54. else
  55. {
  56. throw new ArgumentException("Please provide a correct input/command!");
  57. }
  58.  
  59. //dict.Add(studentName, new Dictionary<string, List<int>>());
  60. //dict[studentName].Add(subject, new List<int>());
  61. //dict[studentName][subject].Add(grades[0]); // to check with more than 1 grade
  62. ////dict["studentName"]["math"].Add(grade[0]);
  63. ////dict["studentName"]["math"].Add(grade[0]);
  64. //dict[studentName].Add(subject, new List<int>());
  65. //dict[studentName][subject].Add(5);
  66. //dict.Add("pesho", new Dictionary<string, List<int>>());
  67. //dict["pesho"].Add("chemistry", new List<int>());
  68. //dict["pesho"]["chemistry"].Add(2);
  69.  
  70. }
  71.  
  72. }
  73.  
  74. }
Add Comment
Please, Sign In to add comment