Advertisement
bullit3189

IronGirder-TFExam 27Aug18

Jan 31st, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _04IronGirder
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. Dictionary<string, int> townTime = new Dictionary<string, int>();
  13. Dictionary<string, int> townPass = new Dictionary<string, int>();
  14.  
  15. while (true)
  16. {
  17. string line = Console.ReadLine();
  18.  
  19. if (line == "Slide rule")
  20. {
  21. break;
  22. }
  23.  
  24. if (!line.Contains("ambush"))
  25. {
  26. //string[] tokens = line.Replace("->", "+").Split(new char[] { ':', '+' });
  27.  
  28. string[] tokens = line.Split(new string[] { ":", "->" }, StringSplitOptions.None);
  29.  
  30.  
  31. string townName = tokens[0];
  32. int time = int.Parse(tokens[1]);
  33. int passangers = int.Parse(tokens[2]);
  34.  
  35. if (!townTime.ContainsKey(townName))
  36. {
  37. townTime.Add(townName, time);
  38. townPass.Add(townName, passangers);
  39.  
  40. }
  41. else
  42. {
  43. townPass[townName] += passangers;
  44.  
  45. if (time < townTime[townName] || townTime[townName]==0)
  46. {
  47.  
  48. townTime[townName] = time;
  49. }
  50. }
  51. }
  52. else
  53. {
  54. string[] tokens = line.Split(":ambush->");
  55.  
  56. string townName = tokens[0];
  57. int passangers =int.Parse(tokens[1]);
  58.  
  59. if (townPass.ContainsKey(townName) && townTime.ContainsKey(townName))
  60. {
  61. townTime[townName] = 0;
  62. townPass[townName] -= passangers;
  63. }
  64. }
  65. }
  66.  
  67. var townTimeSorted=townTime.Where(x => x.Value > 0);
  68. var townPassSorted=townPass.Where(x => x.Value > 0);
  69.  
  70. foreach (var kvp in townTimeSorted.OrderBy(x=>x.Value).ThenBy(x=>x.Key))
  71. {
  72. string townName = kvp.Key;
  73. int time = kvp.Value;
  74. int passangers = townPass[townName];
  75.  
  76. //if (townPass[townName]==0 || townTime[townName]==0)
  77. //{
  78. // continue;
  79. //}
  80.  
  81. Console.WriteLine($"{townName} -> Time: {time} -> Passengers: {passangers}");
  82. }
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement