Advertisement
Spocoman

02. Articles

Mar 2nd, 2022
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Articles
  5. {
  6.     class Program
  7.     {
  8.         public static void Main()
  9.         {
  10.             string[] input = Console.ReadLine().Split(", ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  11.  
  12.             int num = int.Parse(Console.ReadLine());
  13.  
  14.             Article article = new Article(input[0], input[1], input[2]);
  15.  
  16.             for (int i = 0; i < num; i++)
  17.             {
  18.                 string[] command = Console.ReadLine().Split(": ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  19.  
  20.                 if (command[0] == "Edit")
  21.                 {
  22.                     article.Edit(command[1]);
  23.                 }
  24.  
  25.                 else if (command[0] == "ChangeAuthor")
  26.                 {
  27.                     article.ChangeAuthor(command[1]);
  28.                 }
  29.  
  30.                 else if (command[0] == "Rename")
  31.                 {
  32.                     article.Rename(command[1]);
  33.                 }
  34.             }
  35.  
  36.             Console.WriteLine(article.ToString());
  37.         }
  38.  
  39.         public class Article
  40.         {
  41.             public Article(string title, string content, string author)
  42.             {
  43.                 this.Title = title;
  44.                 this.Content = content;
  45.                 this.Author = author;
  46.             }
  47.  
  48.             public object Title { get; set; }
  49.  
  50.             public object Content { get; set; }
  51.  
  52.             public object Author { get; set; }
  53.  
  54.             public void Edit(string newContent)
  55.             {
  56.                 this.Content = newContent;
  57.             }
  58.  
  59.             public void ChangeAuthor(string newAuthor)
  60.             {
  61.                 this.Author = newAuthor;
  62.             }
  63.  
  64.             public void Rename(string newTitle)
  65.             {
  66.                 this.Title = newTitle;
  67.             }
  68.  
  69.             public override string ToString()
  70.             {
  71.                 return $"{this.Title} - {this.Content}: {this.Author}";
  72.             }
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement