Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _09.BankAccount
  6. {
  7.     class BankAccount
  8.     {
  9.         public string Name { get; set; }
  10.         public string Bank { get; set; }
  11.         public decimal Balance { get; set; }
  12.  
  13.         public static BankAccount ReadAccount(string input)
  14.         {
  15.             string[] tokens = input.Split(new string[] { " | " }, StringSplitOptions.RemoveEmptyEntries);
  16.             return new BankAccount
  17.             {
  18.                 Name = tokens[1],
  19.                 Bank = tokens[0],
  20.                 Balance = decimal.Parse(tokens[2])
  21.             };
  22.         }
  23.     }
  24.  
  25.     class Program
  26.     {
  27.         static void Main(string[] args)
  28.         {
  29.             string input = Console.ReadLine();
  30.             List<BankAccount> result = new List<BankAccount>();
  31.  
  32.             while (input != "end")
  33.             {
  34.                 BankAccount currAcc = BankAccount.ReadAccount(input);
  35.                 result.Add(currAcc);
  36.  
  37.                 input = Console.ReadLine();
  38.             }
  39.  
  40.             result.OrderByDescending(b => b.Balance).ThenBy(b => b.Bank.Length)
  41.                 .ToList().ForEach(x => Console.WriteLine($"{x.Name} -> {x.Balance} ({x.Bank})"));
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement