zhivko1985

Book_Library

Apr 4th, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 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 Book_Library
  8. {
  9. public class Book
  10. {
  11. public string Title { get; set; }
  12. public string Author { get; set; }
  13. public string Publisher { get; set; }
  14. public string ReleaseDate { get; set; }
  15. public string ISBN { get; set; }
  16. public decimal Price { get; set; }
  17.  
  18. }
  19. public class Library
  20. {
  21. public string Name { get; set; }
  22. public List<Book> Books {get;set;}
  23.  
  24. public Library()
  25. {
  26. Books = new List<Book>();
  27. }
  28. }
  29. public class Program
  30. {
  31. public static void Main(string[] args)
  32. {
  33. int n = int.Parse(Console.ReadLine());
  34. Library Library = new Library();
  35. Dictionary<string, decimal> dict = new Dictionary<string, decimal>();
  36.  
  37. for (int i = 0; i < n; i++)
  38. {
  39. Book currentBook = new Book();
  40. var input = Console.ReadLine().Split(new char[] { ' ' },StringSplitOptions.RemoveEmptyEntries).ToArray();
  41.  
  42. currentBook.Title = input[0];
  43. currentBook.Author = input[1];
  44. currentBook.Publisher = input[2];
  45. currentBook.ReleaseDate = input[3];
  46. currentBook.ISBN = input[4];
  47. currentBook.Price =decimal.Parse( input[5]);
  48.  
  49. Library.Books.Add(currentBook);
  50. if (!dict.Keys.Contains(currentBook.Author))
  51. {
  52. dict.Add(currentBook.Author, currentBook.Price);
  53. }
  54. else
  55. {
  56. dict[currentBook.Author] += currentBook.Price;
  57. }
  58. }
  59. foreach (var item in dict.OrderBy(x=>-x.Value).ThenBy(x=>x.Key))
  60. {
  61. Console.WriteLine("{0} -> {1}",item.Key,item.Value);
  62. }
  63. }
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment