Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _4.Social_Media_Posts
- {
- class Program
- {
- public class Post
- {
- public string Name { get; set; }
- public int Like { get; set; }
- public int DisLike { get; set; }
- public List <Comment> CommentList { get; set; }
- }
- public Program()
- {
- int Like = 0;
- int DisLike = 0;
- }
- public class Comment
- {
- public string PostName { get; set; }
- public string CommentatorName { get; set; }
- public string Content { get; set; }
- }
- static void Main(string[] args)
- {
- var listOfPosts = new Dictionary<string, Post>();
- var postsNameToComment = new Dictionary<string,List<Comment>>();
- var line = Console.ReadLine();
- while (line!= "drop the media")
- {
- Post post = new Post();
- Comment comment = new Comment();
- var tokens = line.Split().ToList();
- if (tokens[0] == "post")
- {
- post.Name = tokens[1];
- listOfPosts.Add(post.Name, post);
- }
- else if (tokens[0] == "like")
- {
- var nameOfPost = tokens[1];
- if (listOfPosts.ContainsKey(nameOfPost))
- {
- listOfPosts[nameOfPost].Like++;
- }
- }
- else if (tokens[0] == "dislike")
- {
- var nameOfPost = tokens[1];
- if (listOfPosts.ContainsKey(nameOfPost))
- {
- listOfPosts[nameOfPost].DisLike++;
- }
- }
- else
- {
- var postName = tokens[1];
- var commentator = tokens[2];
- var content = tokens[3];
- comment.CommentatorName = commentator;
- comment.PostName = postName;
- comment.Content = content;
- if (!postsNameToComment.ContainsKey(postName))
- {
- postsNameToComment.Add(postName, new List<Comment> {comment });
- }
- else
- {
- postsNameToComment[postName].Add(comment);
- }
- }
- line = Console.ReadLine();
- }
- foreach (var post in listOfPosts)
- {
- Console.WriteLine($"Post: {post.Key} | Likes: {post.Value.Like } | Dislikes: {post.Value.DisLike } ");
- Console.WriteLine("Comments:");
- var resultedComment = new List<Comment>();
- if (!postsNameToComment.ContainsKey(post.Key))
- {
- Console.WriteLine("None");
- }
- else
- {
- resultedComment.AddRange( postsNameToComment[post.Key]);
- foreach (var item in resultedComment)
- {
- Console.WriteLine($"* {item.CommentatorName}: {item.Content}");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment