Created
June 9, 2016 15:24
-
-
Save Nikola-Andreev/56d1fc57422508db0c1a62b429a3d0e9 to your computer and use it in GitHub Desktop.
Book Library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Numerics; | |
using System.Globalization; | |
using System.Text.RegularExpressions; | |
using System.Threading; | |
public class Book | |
{ | |
public string Title { get; set; } | |
public string Name { get; set; } | |
public decimal Price { get; set; } | |
public DateTime ReleaseDate { get; set; } | |
public static Book ReadBook() | |
{ | |
string[] book = Console.ReadLine().Split(' '); | |
Book b = new Book() { Name = book[1], Price = decimal.Parse(book[5]), Title = book[0], ReleaseDate = DateTime.ParseExact(book[3], "dd.MM.yyyy",CultureInfo.InvariantCulture) }; | |
return b; | |
} | |
} | |
public class Library | |
{ | |
public string Name { get; set; } | |
public decimal Price { get; set; } | |
} | |
class Programa | |
{ | |
static void Main(string[] args) | |
{ | |
int number = int.Parse(Console.ReadLine()); | |
List<Book> books = new List<Book>(); | |
for (int i = 0; i < number; i++) | |
{ | |
Book b1 = Book.ReadBook(); | |
books.Add(b1); | |
} | |
List<Library> libs = new List<Library>(); | |
for (int i = 0; i < books.Count; i++) | |
{ | |
Library l1 = new Library() { Name = books[i].Name }; | |
if (libs.Any(e => e.Name == l1.Name)) | |
{ | |
for (int s = 0; s < libs.Count; s++) | |
{ | |
if (libs[s].Name==l1.Name) | |
{ | |
libs[s].Price += books[i].Price; | |
} | |
} | |
} | |
else | |
{ | |
l1.Price = books[i].Price; | |
libs.Add(l1); | |
} | |
} | |
List<Library> output = new List<Library>(libs.OrderByDescending(s => s.Price).ThenBy(a => a.Name).ToList()); | |
foreach (var item in output) | |
{ | |
Console.WriteLine("{0} -> {1}",item.Name,item.Price); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment