Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace skateboard
  6. {
  7. class MainClass
  8. {
  9. //If team does not exists add to library and award 0 points
  10. static void DoesTeamExist(Dictionary<string, int> dictionary, string team)
  11. {
  12. if (!dictionary.ContainsKey(team))
  13. {
  14. dictionary.Add(team, 0);
  15. }
  16. }
  17.  
  18. //If draw add one point to each team, else awards the winner 2 points
  19. static void AwardPoints(Dictionary<string, int> dictionary, string teamOne, string teamTwo, int teamOneScore, int teamTwoScore)
  20. {
  21. if (teamOneScore == teamTwoScore)
  22. {
  23. dictionary[teamOne] += 1;
  24. dictionary[teamTwo] += 1;
  25. }
  26. else if (teamOneScore > teamTwoScore)
  27. {
  28. dictionary[teamOne] += 2;
  29. }
  30. else
  31. {
  32. dictionary[teamTwo] += 2;
  33. }
  34. }
  35.  
  36.  
  37. public static void Main(string[] args)
  38. {
  39.  
  40. int counter = 0;
  41. string line;
  42. System.IO.StreamReader file =
  43. new System.IO.StreamReader(@"/Users/aaronmk2/Projects/skateboard/skateboard/sample-input.txt");
  44. Dictionary<string, int> dictionary = new Dictionary<string, int>();
  45.  
  46.  
  47. while ((line = file.ReadLine()) != null)
  48. {
  49. string []lines = line.Split(',');
  50. string teamOne = lines[0].Substring(0, lines[0].Length - 2);
  51. int teamOneScore = Convert.ToInt32(lines[0][lines[0].Length - 1] - '0');
  52. DoesTeamExist(dictionary, teamOne);
  53. string teamTwo = lines[1].Substring(1, lines[1].Length - 2);
  54. int teamTwoScore = Convert.ToInt32(lines[1][lines[1].Length - 1] - '0');
  55. DoesTeamExist(dictionary, teamTwo);
  56. AwardPoints(dictionary, teamOne, teamTwo, teamOneScore, teamTwoScore);
  57. counter++;
  58. }
  59.  
  60. file.Close();
  61.  
  62. var items = from pair in dictionary
  63. orderby pair.Value descending, pair.Key ascending
  64. select pair;
  65.  
  66.  
  67. System.IO.StreamWriter write = new System.IO.StreamWriter(@"/Users/aaronmk2/Projects/skateboard/skateboard/test-output.txt");
  68.  
  69. // Display results.
  70. foreach (KeyValuePair<string, int> pair in items)
  71. {
  72. Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
  73. if (pair.Value == 1)
  74. {
  75. write.WriteLine("{0}: {1} pt", pair.Key, pair.Value);
  76. }
  77. else
  78. {
  79. write.WriteLine("{0}: {1} pts", pair.Key, pair.Value);
  80. }
  81.  
  82. }
  83. write.Close();
  84. }
  85. }
  86. }
  87.  
  88. new System.IO.StreamReader(@"/Users/aaronmk2/Projects/skateboard/skateboard/sample-input.txt");
  89.  
  90. while ((line = file.ReadLine()) != null)
  91.  
  92. while(line = file.Readline() != null)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement