Advertisement
NadyaMisheva

dobavyane na ychenici cyala zadacha

Mar 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. public class Program
  5. {
  6. public static void Main()
  7. {
  8. Dictionary<string, List<string>> school = new Dictionary<string, List<string>> ();
  9. while(true)
  10. {
  11. string[] command = Console.ReadLine().Split(' ');
  12. if (command[0] == "End")
  13. {
  14. break;
  15. }
  16. else if (command[0] == "Add")
  17. {
  18. string student = command[1];
  19. string paralelka = command[2];
  20. if(school.ContainsKey(paralelka))
  21. {
  22. school[paralelka].Add(student);
  23. }
  24. else
  25. {
  26. List<string> newParalelka = new List<string>();
  27. newParalelka.Add(student);
  28. school[paralelka] = newParalelka;
  29. }
  30. }
  31.  
  32. else if(command[0] == "Transfer")
  33. {
  34. string student = command[1];
  35. string par1 = command[3];
  36. string par2 = command[5];
  37. if(school[par1].Contains(student))
  38. {
  39. school[par1].Remove(student);
  40. if(school[par1].Count == 0)
  41. {
  42. school.Remove(par1);
  43. }
  44. if(school.ContainsKey(par2))
  45. {
  46. school[par2].Add(student);
  47. }
  48. else
  49. {
  50. school[par2] = new List<string>();
  51. school[par2].Add(student);
  52. }
  53. }
  54. }
  55. else if(command[0] == "Merge")
  56. {
  57. string par1 = command[1];
  58. string par2 = command[2];
  59. if(school.ContainsKey(par1) && school.ContainsKey(par2))
  60. {
  61. foreach(string student in school[par1])
  62. {
  63. school[par2].Add(student);
  64. }
  65. school.Remove(par1);
  66. }
  67. }
  68. }
  69. foreach(string paralelka in school.Keys)
  70. {
  71. Console.WriteLine("Class name: " + paralelka);
  72. foreach(string student in school[paralelka])
  73. {
  74. Console.WriteLine("###" + student);
  75. }
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement