Advertisement
bullit3189

Tagram

Jun 10th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. public class Program
  7. {
  8. public static void Main()
  9. {
  10. Dictionary<string,Dictionary<string,int>> nameTagLikes = new Dictionary<string,Dictionary<string,int>>();
  11.  
  12. while(true)
  13. {
  14. string command = Console.ReadLine();
  15.  
  16. if(command == "end")
  17. {
  18. break;
  19. }
  20.  
  21. if(!command.Contains("ban"))
  22. {
  23. string[] tokens = command.Split(" -> ");
  24. string name = tokens[0];
  25. string tag = tokens[1];
  26. int likes = int.Parse(tokens[2]);
  27.  
  28. if(!nameTagLikes.ContainsKey(name))
  29. {
  30. nameTagLikes.Add(name, new Dictionary<string,int>());
  31. nameTagLikes[name].Add(tag,likes);
  32. }
  33. else if(nameTagLikes.ContainsKey(name)==true && nameTagLikes[name].ContainsKey(tag)==false)
  34. {
  35. nameTagLikes[name].Add(tag,likes);
  36. }
  37. else if (nameTagLikes.ContainsKey(name)==true && nameTagLikes[name].ContainsKey(tag)==true)
  38. {
  39. nameTagLikes[name][tag]+=likes;
  40. }
  41. }
  42. else
  43. {
  44. string[] tokens = command.Split(new char[]{' '},StringSplitOptions.RemoveEmptyEntries);
  45. string name = tokens[1];
  46.  
  47. if(nameTagLikes.ContainsKey(name))
  48. {
  49. nameTagLikes.Remove(name);
  50. }
  51. }
  52. }
  53.  
  54. foreach(var kvp in nameTagLikes.OrderByDescending(x=>x.Value.Values.Sum()).ThenBy(x=>x.Value.Keys.Count))
  55. {
  56. string name = kvp.Key;
  57. Console.WriteLine(name);
  58.  
  59. foreach(var inner in kvp.Value)
  60. {
  61. Console.WriteLine("- {0}: {1}",inner.Key,inner.Value);
  62. }
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement