Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Exercise
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Startup
- {
- public static void Main()
- {
- string input = Console.ReadLine();
- var namesAndScores = new Dictionary<string, int>();
- var languageAndCount = new Dictionary<string, int>();
- while (input != "exam finished")
- {
- List<string> lines = input
- .Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries)
- .ToList();
- string name = lines[0];
- string language = lines[1];
- if (lines[1] != "banned")
- {
- int score = int.Parse(lines[2]);
- if (!namesAndScores.ContainsKey(name))
- {
- namesAndScores[name] = score ;
- }
- else
- {
- int oldScore = namesAndScores[name];
- namesAndScores[name] = Math.Max(oldScore, score);
- }
- if (!languageAndCount.ContainsKey(language))
- {
- languageAndCount[language] = 1;
- }
- else
- {
- languageAndCount[language] ++;
- }
- }
- else
- {
- namesAndScores.Remove(name);
- }
- input = Console.ReadLine();
- }
- Console.WriteLine("Results:");
- foreach (var kvp in namesAndScores
- .OrderBy(x => x.Key)
- .OrderByDescending(x => x.Value))
- {
- Console.WriteLine($"{kvp.Key} | {kvp.Value}");
- }
- Console.WriteLine("Submissions:");
- foreach (var kvp in languageAndCount
- .OrderBy(x => x.Key))
- {
- Console.WriteLine($"{kvp.Key} - {kvp.Value}");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment