Guest User

Untitled

a guest
Jun 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Program
  5. {
  6. public static void Main()
  7. {
  8. int n = int.Parse(Console.ReadLine());
  9.  
  10. List<Book> books = new List<Book>();
  11.  
  12. for(int i =0; i<n; i++)
  13. {
  14. string[] tokens = Console.ReadLine().Split();
  15. string title = tokens[0];
  16. string author = tokens[1];
  17. string publisher = tokens[2];
  18. DateTime releaseDate = DateTime.ParseExact(tokens[3],"dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture);
  19. string isbn = tokens[4];
  20. decimal price = decimal.Parse(tokens[5]);
  21.  
  22. Book book = new Book(title, author, publisher, releaseDate,isbn,price);
  23. books.Add(book);
  24.  
  25. Dictionary<string, decimal> authors = new Dictionary<string,decimal>();
  26.  
  27. foreach (Book item in books)
  28. {
  29. string authorName = book.Author;
  30. decimal bookPrice = book.Price;
  31.  
  32. if (authors.ContainsKey(authorName) == false)
  33. {
  34. authors.Add(authorName,0);
  35. }
  36. authors[authorName] =authors[authorName]+ bookPrice;
  37. }
  38. }
  39. Dictionary<string, decimal> sortedAuthors = authors.OrderByDescending(a=>a.Value).ThenBy(a=>a.Key).ToDictionary(x=> x.Key, x=>x.Value);
  40.  
  41. foreach (var author in sortedAuthors)
  42. {
  43. Console.WriteLine($"{author.Key} -> {author.Value:f2}");
  44. }
  45.  
  46. }
  47. }
  48. public class Book
  49. {
  50. public string Title {get;set;}
  51. public string Author {get;set;}
  52. public string Publisher {get;set;}
  53. public DateTime ReleaseDate {get;set;}
  54. public string Isbn {get;set;}
  55. public decimal Price {get;set;}
  56.  
  57. public Book (string title, string author ,string publisher ,DateTime releaseDate,string isbn ,decimal price)
  58. {
  59. Title = title;
  60. Author = author;
  61. Publisher = publisher;
  62. ReleaseDate = releaseDate;
  63. Isbn = isbn;
  64. Price = price;
  65. }
  66. }
Add Comment
Please, Sign In to add comment