Chessmaster

Untitled

Nov 9th, 2018
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.28 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Numerics;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. namespace Article
  8. {
  9.     class Program
  10.     {
  11.         public static void Article(List<string> list, int n)
  12.         {
  13.             string title = list[0];
  14.             string content = list[1].Trim();
  15.             string author = list[2].Trim();
  16.  
  17.             Article article = new Article(title, content, author);
  18.             for (int i = 0; i < n; i++)
  19.             {
  20.                 string[] tokens = Console.ReadLine().Split(':', StringSplitOptions.RemoveEmptyEntries);
  21.  
  22.                 string command = tokens[0].ToLower(); // trim that
  23.                 string replacer = tokens[1].Trim();
  24.  
  25.                 if (command == "Edit".ToLower())
  26.                 {
  27.                     article.Edit(replacer);
  28.                 }
  29.                 else if (command == "ChangeAuthor".ToLower())
  30.                 {
  31.                     article.ChangeAuthor(replacer);
  32.                 }
  33.                 else if (command == "Rename".ToLower())
  34.                 {
  35.                     article.Rename(replacer);
  36.                 }
  37.             }
  38.  
  39.             Console.WriteLine(article.ToString());
  40.         }
  41.  
  42.         static void Main()
  43.         {
  44.             List<string> list = Console.ReadLine().Split(',', StringSplitOptions.RemoveEmptyEntries).ToList();
  45.             int n = int.Parse(Console.ReadLine());
  46.  
  47.             Article(list, n);
  48.         }
  49.     }
  50.  
  51.     public class Article
  52.     {
  53.         public Article(string title, string content, string author)
  54.         {
  55.             this.Title = title;
  56.             this.Content = content;
  57.             this.Author = author;
  58.         }
  59.  
  60.         public string Title { get; set; }
  61.  
  62.         public string Content { get; set; }
  63.  
  64.         public string Author { get; set; }
  65.  
  66.         public void Edit(string changer)
  67.         {
  68.             this.Content = changer;
  69.         }
  70.  
  71.         public void ChangeAuthor(string changer)
  72.         {
  73.             this.Author = changer;
  74.         }
  75.  
  76.         public void Rename(string changer)
  77.         {
  78.             this.Title = changer;
  79.         }
  80.  
  81.         public override string ToString()
  82.         {
  83.             return $"{this.Title} - {this.Content}: {this.Author}";
  84.         }
  85.     }
  86. } // .
Advertisement
Add Comment
Please, Sign In to add comment