nikolayneykov

Untitled

Mar 19th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03Articles2._0
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int numberOfArticles = int.Parse(Console.ReadLine());
  12.  
  13.             Storage storage = new Storage();
  14.             for (int i = 1; i <= numberOfArticles; i++)
  15.             {
  16.                 string[] currentArticle = Console.ReadLine().Split(", ");
  17.                 string title = currentArticle[0];
  18.                 string content = currentArticle[1];
  19.                 string author = currentArticle[2];
  20.  
  21.                 storage.Articles.Add(new Article(title, content, author));
  22.             }
  23.  
  24.             string inputCriteria = Console.ReadLine();
  25.  
  26.             if (inputCriteria == "title")
  27.             {
  28.                 storage.Articles = storage.Articles.OrderBy(t => t.Title).ToList();
  29.             }
  30.             else if (inputCriteria == "content")
  31.             {
  32.                 storage.Articles = storage.Articles.OrderBy(t => t.Content).ToList();
  33.             }
  34.             else if (inputCriteria == "author")
  35.             {
  36.                 storage.Articles = storage.Articles.OrderBy(t => t.Author).ToList();
  37.             }
  38.  
  39.             Console.WriteLine(storage);
  40.         }
  41.     }
  42.  
  43.     class Article
  44.     {
  45.         public string Title { get; set; }
  46.         public string Content { get; set; }
  47.         public string Author { get; set; }
  48.  
  49.         public Article(string title, string content, string author)
  50.         {
  51.             Title = title;
  52.             Content = content;
  53.             Author = author;
  54.         }
  55.  
  56.         public override string ToString()
  57.         {
  58.             return $"{Title} - {Content}: {Author}";
  59.         }
  60.     }
  61.  
  62.     class Storage
  63.     {
  64.         public Storage()
  65.         {
  66.             this.Articles = new List<Article>();
  67.         }
  68.  
  69.         public List<Article> Articles { get; set; }
  70.  
  71.         public override string ToString()
  72.         {
  73.             return string.Join(Environment.NewLine, this.Articles);
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment