Advertisement
Guest User

Untitled

a guest
May 8th, 2015
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ActivityTracker_13
  8. {
  9.     class ActivityTracker_13
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             SortedDictionary<int, SortedDictionary<string, int>> spyData = new SortedDictionary<int, SortedDictionary<string, int>>();
  14.             SortedDictionary<string, int> userData = new SortedDictionary<string, int>();
  15.             int n = int.Parse(Console.ReadLine());
  16.  
  17.             for (int a = 0; a < n; a++)
  18.             {
  19.                 string[] inputData = Console.ReadLine().Split();
  20.                 DateTime date = DateTime.Parse(inputData[0]);
  21.                 int month = date.Month;
  22.                 string userName = inputData[1];
  23.                 int distance = int.Parse(inputData[2]);
  24.  
  25.                 if (!spyData.ContainsKey(month))
  26.                 {
  27.                     userData = new SortedDictionary<string, int>();
  28.                     userData.Add(userName, distance);
  29.                     spyData.Add(month, userData);
  30.                 }
  31.                 else
  32.                 {
  33.                     if (!userData.ContainsKey(userName))
  34.                     {
  35.                         userData.Add(userName, distance);
  36.                     }
  37.                     else
  38.                     {
  39.                         int currentDist = userData[userName];
  40.                         int newDistance = currentDist + distance;
  41.                         userData[userName] = newDistance;
  42.  
  43.                     }
  44.                     spyData[month] = userData;
  45.                 }
  46.             }
  47.             foreach (var k in spyData.Keys)
  48.             {
  49.                 Console.Write(k+":");
  50.                 SortedDictionary<string, int> data = spyData[k];
  51.                 foreach (var c in data)
  52.                 {
  53.                     Console.Write("{0} ({1}),",c.Key, c.Value);
  54.                 }
  55.                 Console.WriteLine();  
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement