Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 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 _09.BankAccount
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             List<BankAccount> result = new List<BankAccount>();
  15.            
  16.             while (input != "end")
  17.             {
  18.                 BankAccount currAcc = ReadAccount(input);
  19.                 result.Add(currAcc);
  20.                
  21.                 input = Console.ReadLine();
  22.             }
  23.             result = result.OrderByDescending(b => b.Balance).ThenBy(n => n.Bank.Length).ToList();
  24.  
  25.             foreach (var item in result)
  26.             {
  27.                 Console.WriteLine($"{item.Name} -> {item.Balance} ({item.Bank})");
  28.             }
  29.         }
  30.  
  31.         private static BankAccount ReadAccount(string input)
  32.         {
  33.             string[] tokens = input.Split(new string[] { " | " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  34.             return new BankAccount
  35.             {
  36.                 Name = tokens[1],
  37.                 Bank = tokens[0],
  38.                 Balance = decimal.Parse(tokens[2])
  39.             };
  40.         }
  41.     }
  42.  
  43.     class BankAccount
  44.     {
  45.         public string Name { get; set; }
  46.         public string Bank { get; set; }
  47.         public decimal Balance { get; set; }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement