Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- public class Program
- {
- public static void Main()
- {
- Dictionary <string, Dictionary<string,int>> contestUserPoints = new Dictionary<string, Dictionary<string,int>>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "no more time")
- {
- break;
- }
- string[] tokens = input.Split(new [] {' ','-','>'},StringSplitOptions.RemoveEmptyEntries);
- string name = tokens[0];
- string contest = tokens[1];
- int points = int.Parse(tokens[2]);
- if (!contestUserPoints.ContainsKey(contest))
- {
- contestUserPoints.Add(contest, new Dictionary<string,int>());
- contestUserPoints[contest].Add(name,points);
- }
- else if (contestUserPoints.ContainsKey(contest)==true && contestUserPoints[contest].ContainsKey(name)==false)
- {
- contestUserPoints[contest].Add(name,points);
- }
- else if (contestUserPoints.ContainsKey(contest)==true && contestUserPoints[contest].ContainsKey(name)==true)
- {
- if (points>contestUserPoints[contest][name])
- {
- contestUserPoints[contest][name] = points;
- }
- }
- }
- foreach (var kvp in contestUserPoints)
- {
- string contest = kvp.Key;
- int participants = kvp.Value.Keys.Count();
- Console.WriteLine("{0}: {1} participants",contest,participants);
- int position=1;
- foreach (var currName in kvp.Value.OrderByDescending(x=>x.Value).ThenBy(x=>x.Key))
- {
- string name = currName.Key;
- int points = currName.Value;
- Console.WriteLine("{0}. {1} <::> {2}",position,name,points);
- position++;
- }
- }
- Console.WriteLine("Individual standings:");
- Dictionary<string,int> userPoints = new Dictionary<string,int>();
- foreach (var kvp in contestUserPoints)
- {
- foreach (var user in kvp.Value)
- {
- if (!userPoints.ContainsKey(user.Key))
- {
- userPoints.Add(user.Key,user.Value);
- }
- else
- {
- userPoints[user.Key]+=user.Value;
- }
- }
- }
- int standing =1;
- foreach (var Kvp in userPoints.OrderByDescending(x=>x.Value).ThenBy(x=>x.Key))
- {
- string user = Kvp.Key;
- int points = Kvp.Value;
- Console.WriteLine("{0}. {1} -> {2}",standing,user,points);
- standing++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement