Advertisement
Guest User

04. Social Media Posts

a guest
Mar 13th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Social_Media_Posts
  5. {
  6.     public class SocialMediaPosts
  7.     {
  8.         public static void Main()
  9.         {
  10.             Dictionary<string, Dictionary<string, string>> commentsDB = new Dictionary<string, Dictionary<string, string>>();
  11.             Dictionary<string, int> likesDB = new Dictionary<string, int>();
  12.             Dictionary<string, int> dislikesDB = new Dictionary<string, int>();
  13.  
  14.             string input = Console.ReadLine();
  15.  
  16.             while (input != "drop the media")
  17.             {
  18.                 string[] tokens = input.Split(' ');
  19.  
  20.                 string command = tokens[0];
  21.  
  22.                 if (!likesDB.ContainsKey(tokens[1]))
  23.                 {
  24.                     likesDB[tokens[1]] = 0;
  25.                 }
  26.  
  27.                 if (!dislikesDB.ContainsKey(tokens[1]))
  28.                 {
  29.                     dislikesDB[tokens[1]] = 0;
  30.                 }
  31.  
  32.                 switch (command)
  33.                 {
  34.                     case "post":
  35.                         commentsDB[tokens[1]] = new Dictionary<string, string>();
  36.                         break;
  37.  
  38.                     case "like":
  39.                         likesDB[tokens[1]] += 1;
  40.                         break;
  41.  
  42.                     case "dislike":
  43.                         dislikesDB[tokens[1]] += 1;
  44.                         break;
  45.  
  46.                     case "comment":
  47.                         commentsDB[tokens[1]][tokens[2]] = tokens[3];
  48.                         break;
  49.                 }
  50.  
  51.                 input = Console.ReadLine();
  52.             }
  53.  
  54.             foreach (var post in commentsDB)
  55.             {
  56.                 Console.WriteLine($"Post: {post.Key} | Likes: {likesDB[post.Key]} | Dislikes: {dislikesDB[post.Key]}");
  57.                 Console.WriteLine("Comments:");
  58.  
  59.                     foreach (var key in post.Value.Keys)
  60.                     {
  61.                         Console.WriteLine("* " + key + ": ");
  62.  
  63.                         //How to print the comment? Please help                      
  64.                     }
  65.  
  66.                
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement