Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Test
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. var dict = new Dictionary<string, Dictionary<string, List<int>>>();
  11. while (true)
  12. {
  13. Console.WriteLine("name/subject/grade or exit\n");
  14. var input = Console.ReadLine();
  15. var arguments = input.Split();
  16.  
  17. if (input == "exit")
  18. {
  19. break;
  20. }
  21. if (!dict.ContainsKey(arguments[0]))
  22. {
  23. dict.Add(arguments[0], new Dictionary<string, List<int>>());
  24. dict[arguments[0]].Add(arguments[1], new List<int>());
  25. dict[arguments[0]][arguments[1]].Add(int.Parse(arguments[2]));
  26. }
  27. else
  28. {
  29. if(!dict[arguments[0]].ContainsKey(arguments[1]))
  30. {
  31. dict[arguments[0]].Add(arguments[1],new List<int>());
  32. dict[arguments[0]][arguments[1]].Add(int.Parse(arguments[2]));
  33. }
  34. else
  35. {
  36. dict[arguments[0]][arguments[1]].Add(int.Parse(arguments[2]));
  37. }
  38. }
  39. }
  40. foreach (var item in dict)
  41. {
  42. Console.WriteLine(item.Key);
  43. foreach (var item2 in dict[item.Key])
  44. {
  45. Console.WriteLine("Subject - " + item2.Key + " | Grade - " + String.Join(',',item2.Value));
  46. }
  47. Console.WriteLine();
  48. }
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement