Advertisement
fbinnzhivko

Untitled

Sep 12th, 2016
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         int number = int.Parse(Console.ReadLine());
  9.         SortedDictionary<string, double> authorSales = new SortedDictionary<string, double>();
  10.         for (int i = 0; i < number; i++)
  11.         {
  12.             string[] input = Console.ReadLine().Split(' ');
  13.             string author = input[1];
  14.             double price = Convert.ToDouble(input[5]);
  15.             if (authorSales.Keys.Contains(author))
  16.             {
  17.                 authorSales[author] += price;
  18.             }
  19.             else
  20.             {
  21.                 authorSales.Add(author, price);
  22.             }
  23.         }
  24.         IOrderedEnumerable<KeyValuePair<string, double>> sortedDict = authorSales.OrderByDescending(x => x.Value).ThenBy(x => x.Key);
  25.         foreach (KeyValuePair<string, double> kvp in sortedDict)
  26.         {
  27.             Console.WriteLine("{0} -> {1:F2}", kvp.Key, kvp.Value);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement