Advertisement
YavorGrancharov

BookLibrary

Jan 4th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace BookLibrary
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.  
  13.             Dictionary<string, double> library = new Dictionary<string, double>();
  14.  
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.                 List<string> input = Console.ReadLine().Split(' ').ToList();
  18.                 string title = input[0];
  19.                 string author = input[1];
  20.                 string publisher = input[2];
  21.                 string date = input[3];
  22.                 string isbn = input[4];
  23.                 double price = double.Parse(input[5]);
  24.  
  25.                 if (!library.ContainsKey(author))
  26.                 {
  27.                     library.Add(author, 0);
  28.                 }
  29.                 library[author] += price;
  30.             }
  31.             foreach (var entry in library.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  32.             {
  33.                 Console.WriteLine("{0} -> {1:F2}", entry.Key, entry.Value);
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement