Advertisement
AnastasiyaG

Untitled

Mar 19th, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _2.Race
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string[] input = Console.ReadLine()
  13. .Split(", ");
  14. Dictionary<string, int> racers = new Dictionary<string, int>();
  15.  
  16. for (int i = 0; i < input.Length; i++)
  17. {
  18. racers[input[i]] = 0;
  19.  
  20. }
  21. StringBuilder sb = new StringBuilder();
  22. int km = 0;
  23. while (true)
  24. {
  25. string input2 = Console.ReadLine();
  26. if (input2 == "end of race")
  27. {
  28. break;
  29. }
  30.  
  31. char[] current = input2.ToCharArray();
  32. for (int i = 0; i < current.Length; i++)
  33. { char now = current[i];
  34. if (char.IsLetterOrDigit(now))
  35. { if (char.IsLetter(now))
  36. { sb.Append(now); }
  37. if (char.IsDigit(now))
  38. { km += now; }
  39. }
  40. }
  41. if (racers.ContainsKey($"{sb}"))
  42. { racers[$"{sb}"] += km; }
  43.  
  44.  
  45. km = 0;
  46. sb = new StringBuilder();
  47. }
  48. if(racers.Count==1)
  49. {
  50. foreach (var item in racers.OrderByDescending(x => x.Value).Take(1))
  51. {
  52. Console.WriteLine($"1st place: {item.Key}");
  53. }
  54. return;
  55. }
  56. if (racers.Count == 2)
  57. {
  58. foreach (var item in racers.OrderByDescending(x => x.Value).Take(1))
  59. {
  60. Console.WriteLine($"1st place: {item.Key}");
  61. }
  62. foreach (var item in racers.OrderByDescending(x => x.Value).Skip(1).Take(1))
  63. {
  64. Console.WriteLine($"2nd place: {item.Key}");
  65. }
  66. return;
  67. }
  68.  
  69. if (racers.Count <= 0)
  70. { return; }
  71.  
  72. foreach (var item in racers.OrderByDescending(x=>x.Value).Take(1))
  73. {
  74. Console.WriteLine($"1st place: {item.Key}");
  75. }
  76. foreach (var item in racers.OrderByDescending(x => x.Value).Skip(1).Take(1))
  77. {
  78. Console.WriteLine($"2nd place: {item.Key}");
  79. }
  80. foreach (var item in racers.OrderByDescending(x => x.Value).Skip(2).Take(1))
  81. {
  82. Console.WriteLine($"3rd place: {item.Key}");
  83. }
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement