SHARE
TWEET

Untitled

a guest Dec 14th, 2018 265 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03Articles2._0
  6. {
  7.     public class Article
  8.     {
  9.         public Article(string title, string content, string author)
  10.         {
  11.             Title = title;
  12.             Content = content;
  13.             Author = author;
  14.         }
  15.  
  16.         public string Title { get; set; }
  17.         public string Content { get; set; }
  18.         public string Author { get; set; }
  19.  
  20.         public override string ToString()
  21.         {
  22.             return $"{Title} - {Content}: {Author}";
  23.         }
  24.     }
  25.  
  26.         class Program
  27.     {
  28.         static void Main(string[] args)
  29.         {
  30.             int countCommands = int.Parse(Console.ReadLine());
  31.             var articles = new List<Article>();
  32.  
  33.             for (int i = 0; i < countCommands; i++)
  34.             {
  35.                 string[] splittedCommand = Console.ReadLine()
  36.                     .Split(", ");
  37.  
  38.                 string title = splittedCommand[0];
  39.                 string content = splittedCommand[1];
  40.                 string author = splittedCommand[2];
  41.  
  42.                 var article = new Article(title, content, author);
  43.  
  44.                 articles.Add(article);
  45.  
  46.                 string orderBy = Console.ReadLine();
  47.  
  48.                 if (orderBy == "title")
  49.                 {
  50.                     articles = articles.OrderBy(x => x.Title)
  51.                         .ToList();
  52.                 }
  53.                 else if (orderBy == "content")
  54.                 {
  55.                     articles = articles.OrderBy(x => x.Content)
  56.                          .ToList();
  57.                 }
  58.                 else if (orderBy == "author")
  59.                 {
  60.                     articles = articles.OrderBy(x => x.Author)
  61.                         .ToList();
  62.                 }
  63.  
  64.                 Console.WriteLine(string.Join(Environment.NewLine, articles));
  65.             }
  66.         }
  67.     }
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top