Advertisement
loter

Travel Company

Mar 18th, 2018
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace More_Exersises
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var travel = new Dictionary<string, Dictionary<string, int>>();
  12.  
  13. string[] input = Console.ReadLine().Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  14.  
  15. while (input[0] != "ready")
  16. {
  17. string destination = input[0];
  18. string[] cityAndCapasity = input[1].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  19.  
  20. for (int i = 0; i < cityAndCapasity.Length; i++)
  21. {
  22. string[] current = cityAndCapasity[i].Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
  23.  
  24. if (travel.ContainsKey(destination) == false)
  25. {
  26. travel.Add(destination, new Dictionary<string, int>());
  27.  
  28. if (travel[destination].ContainsKey(current[0]) == false)
  29. {
  30. travel[destination].Add(current[0], int.Parse(current[1]));
  31. }
  32. }
  33.  
  34. else
  35. {
  36. if (travel[destination].ContainsKey(current[0]) == false)
  37. {
  38. travel[destination].Add(current[0], int.Parse(current[1]));
  39. }
  40.  
  41. else
  42. {
  43. travel[destination][current[0]] += int.Parse(current[1]);
  44. }
  45. }
  46. }
  47.  
  48. input = Console.ReadLine().Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  49. }
  50.  
  51. var helper = new Dictionary<string, int>();
  52. foreach (var item in travel)
  53. {
  54. if (helper.ContainsKey(item.Key)== false)
  55. {
  56. helper.Add(item.Key, item.Value.Values.Sum());
  57. }
  58. else
  59. {
  60. helper[item.Key] += item.Value.Values.Sum();
  61. }
  62.  
  63. }
  64.  
  65. string[] aim = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  66.  
  67. while (aim[0] != "travel")
  68. {
  69. int placesAvaible = 0;
  70. foreach (var country in helper)
  71. {
  72. if (country.Key == aim[0])
  73. {
  74. placesAvaible = country.Value;
  75. placesAvaible -= int.Parse(aim[1]);
  76. helper[aim[0]] = placesAvaible;
  77.  
  78. if (placesAvaible >= 0)
  79. {
  80. Console.WriteLine($"{aim[0]} -> all {aim[1]} accommodated");
  81. break;
  82. }
  83. else
  84. {
  85. Console.WriteLine($"{aim[0]} -> all except {Math.Abs(placesAvaible)} accommodated");
  86. break;
  87. }
  88. }
  89. }
  90. aim = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  91. }
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement