Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Learning
- {
- /* Enter Teams and Season Points in a Sorted Dictionary, then print all entries sorted by names */
- class Dictionaries_Lab_
- {
- static void Main()
- {
- char[] sepSpace = { ' ' };
- char[] sepComma = {','};
- Console.Write("Team names: ");
- var teamNamesAndPoints = Console.ReadLine().Trim() // this is a string
- .Split(sepComma, StringSplitOptions.RemoveEmptyEntries).ToList(); // this is now a string array
- var premierTeamsAndPoints = new SortedDictionary<string, int>();
- var currentTeamName = "";
- var currentTeamPoints = 0;
- for (int i = 0; i < teamNamesAndPoints.Count(); i++)
- {
- if(i == 0 || i % 2 == 0)
- {
- currentTeamName = teamNamesAndPoints[i];
- if(premierTeamsAndPoints.ContainsKey(currentTeamName) == false)
- {
- premierTeamsAndPoints[currentTeamName] = 0;
- }
- }
- else
- {
- currentTeamPoints = int.Parse(teamNamesAndPoints[i]);
- if (premierTeamsAndPoints[currentTeamName] == 0)
- {
- premierTeamsAndPoints[currentTeamName] = currentTeamPoints;
- }
- }
- }
- foreach(var team in premierTeamsAndPoints)
- {
- var teamName = team.Key;
- var teamPoints = team.Value;
- Console.WriteLine($"{teamName}: {teamPoints}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement