Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 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 OrderedBankingSystem
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var banksAndUsersAndBalances = new Dictionary<string, Dictionary<string, decimal>>();
  14.             string intro = Console.ReadLine();
  15.             while (intro != "end")
  16.             {
  17.                 string[] threeParts = intro.Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
  18.                 string bank = threeParts[0];
  19.                 string user = threeParts[1];
  20.                 decimal balance = decimal.Parse(threeParts[2]);
  21.                 if (!banksAndUsersAndBalances.ContainsKey(bank))
  22.                     banksAndUsersAndBalances.Add(bank, new Dictionary<string, decimal>());
  23.                 if (!banksAndUsersAndBalances[bank].ContainsKey(user))
  24.                     banksAndUsersAndBalances[bank].Add(user, 0);
  25.                 banksAndUsersAndBalances[bank][user] = banksAndUsersAndBalances[bank][user] + balance;
  26.                 intro = Console.ReadLine();
  27.             }
  28.             banksAndUsersAndBalances = banksAndUsersAndBalances.
  29.                 OrderByDescending(a => a.Value.Values.Sum()).ThenByDescending(b => b.Value.Values.Max()).
  30.                 ToDictionary(a => a.Key, b => b.Value);
  31.  
  32.             foreach (var bank in banksAndUsersAndBalances)
  33.             {
  34.                 foreach (var user in bank.Value.OrderByDescending(x => x.Value))
  35.                 {
  36.                     Console.WriteLine("{0} -> {1} ({2})", user.Key,user.Value,bank.Key);
  37.                 }
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement