Advertisement
Spocoman

03. Articles 2.0

Dec 29th, 2022
1,118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Articles2
  6. {
  7.     class Program
  8.     {
  9.         public static void Main()
  10.         {
  11.             List<Article> articles = new List<Article>();
  12.             int num = int.Parse(Console.ReadLine());
  13.  
  14.             for (int i = 0; i < num; i++)
  15.             {
  16.                 string[] info = Console.ReadLine().Split(", ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  17.                 Article article = new Article(info[0], info[1], info[2]);
  18.                 articles.Add(article);
  19.             }
  20.  
  21.             string str = Console.ReadLine();
  22.             articles.OrderByDescending(x => str == "title" ? x.Title : str == "content" ? x.Content : x.Author).ToList();
  23.  
  24.             Console.WriteLine(String.Join("\n", articles));
  25.         }
  26.  
  27.         public class Article
  28.         {
  29.             public Article(string title, string content, string author)
  30.             {
  31.                 Title = title;
  32.                 Content = content;
  33.                 Author = author;
  34.             }
  35.  
  36.             public string Title { get; set; }
  37.  
  38.             public string Content { get; set; }
  39.  
  40.             public string Author { get; set; }
  41.  
  42.             public override string ToString()
  43.             {
  44.                 return $"{Title} - {Content}: {Author}";
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement