Advertisement
Radost09

Articles

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