Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace skateboard
- {
- class MainClass
- {
- //If team does not exists add to library and award 0 points
- static void DoesTeamExist(Dictionary<string, int> dictionary, string team)
- {
- if (!dictionary.ContainsKey(team))
- {
- dictionary.Add(team, 0);
- }
- }
- //If draw add one point to each team, else awards the winner 2 points
- static void AwardPoints(Dictionary<string, int> dictionary, string teamOne, string teamTwo, int teamOneScore, int teamTwoScore)
- {
- if (teamOneScore == teamTwoScore)
- {
- dictionary[teamOne] += 1;
- dictionary[teamTwo] += 1;
- }
- else if (teamOneScore > teamTwoScore)
- {
- dictionary[teamOne] += 2;
- }
- else
- {
- dictionary[teamTwo] += 2;
- }
- }
- public static void Main(string[] args)
- {
- int counter = 0;
- string line;
- System.IO.StreamReader file =
- new System.IO.StreamReader(@"/Users/aaronmk2/Projects/skateboard/skateboard/sample-input.txt");
- Dictionary<string, int> dictionary = new Dictionary<string, int>();
- while ((line = file.ReadLine()) != null)
- {
- string []lines = line.Split(',');
- string teamOne = lines[0].Substring(0, lines[0].Length - 2);
- int teamOneScore = Convert.ToInt32(lines[0][lines[0].Length - 1] - '0');
- DoesTeamExist(dictionary, teamOne);
- string teamTwo = lines[1].Substring(1, lines[1].Length - 2);
- int teamTwoScore = Convert.ToInt32(lines[1][lines[1].Length - 1] - '0');
- DoesTeamExist(dictionary, teamTwo);
- AwardPoints(dictionary, teamOne, teamTwo, teamOneScore, teamTwoScore);
- counter++;
- }
- file.Close();
- var items = from pair in dictionary
- orderby pair.Value descending, pair.Key ascending
- select pair;
- System.IO.StreamWriter write = new System.IO.StreamWriter(@"/Users/aaronmk2/Projects/skateboard/skateboard/test-output.txt");
- // Display results.
- foreach (KeyValuePair<string, int> pair in items)
- {
- Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
- if (pair.Value == 1)
- {
- write.WriteLine("{0}: {1} pt", pair.Key, pair.Value);
- }
- else
- {
- write.WriteLine("{0}: {1} pts", pair.Key, pair.Value);
- }
- }
- write.Close();
- }
- }
- }
- new System.IO.StreamReader(@"/Users/aaronmk2/Projects/skateboard/skateboard/sample-input.txt");
- while ((line = file.ReadLine()) != null)
- while(line = file.Readline() != null)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement