Advertisement
YavorGrancharov

Social_Media_Posts(copy)(dict)

Jul 15th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Social_Media_Posts
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, Dictionary<string, int>> social = new Dictionary<string, Dictionary<string, int>>();
  12.             Dictionary<string, Dictionary<string, List<string>>> comments = new Dictionary<string, Dictionary<string, List<string>>>();
  13.  
  14.             while (true)
  15.             {
  16.                 string input = Console.ReadLine();
  17.                 if (input == "drop the media")
  18.                 {
  19.                     break;
  20.                 }
  21.                 string[] tokens = input.Split(' ');
  22.                 string command = tokens[0];
  23.                 string postName = tokens[1];
  24.  
  25.                 if (command == "post")
  26.                 {
  27.                     if (!social.ContainsKey(postName))
  28.                     {
  29.                         social.Add(postName, new Dictionary<string, int>());
  30.                         social[postName].Add("Likes:", 0);
  31.                         social[postName].Add("Dislikes:", 0);
  32.                     }
  33.                 }
  34.                 else if (command == "like")
  35.                 {
  36.                     social[postName]["Likes:"]++;
  37.                 }
  38.                 else if (command == "dislike")
  39.                 {
  40.                     social[postName]["Dislikes:"]++;
  41.                 }
  42.                 else if (command == "comment")
  43.                 {
  44.                     string person = tokens[2];
  45.                     if (!comments.ContainsKey(postName))
  46.                     {
  47.                         comments.Add(postName, new Dictionary<string, List<string>>());
  48.                     }
  49.                     comments[postName].Add(person, new List<string>());
  50.                     for (int i = 3; i < tokens.Length; i++)
  51.                     {
  52.                         comments[postName][person].Add(tokens[i]);
  53.                     }
  54.                 }
  55.             }
  56.  
  57.             foreach (var item in social.Keys)
  58.             {
  59.                 var likes = social[item];
  60.                 Console.Write("Post: {0}", item);
  61.                 foreach (var like in likes)
  62.                 {
  63.                     Console.Write(" | {0} {1}", like.Key, like.Value);
  64.                 }
  65.                 Console.WriteLine();
  66.                 Console.WriteLine("Comments:");
  67.                 if (comments.ContainsKey(item))
  68.                 {
  69.                     var comment = comments[item];
  70.                     foreach (var commentator in comment)
  71.                     {
  72.                         Console.WriteLine("*  {0}: {1}", commentator.Key, string.Join(" ", commentator.Value));
  73.                     }
  74.                 }
  75.                 else
  76.                 {
  77.                     Console.WriteLine("None");
  78.                 }
  79.             }
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement