Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5.  
  6. namespace RegisteredUSers
  7. {
  8. internal class Program
  9. {
  10. public static void Main(string[] args)
  11. {
  12. string input = Console.ReadLine();
  13. Dictionary<string, string> dic = new Dictionary<string, string>();
  14. Dictionary<string, string> dic2 = new Dictionary<string, string>();
  15. while (input != "end")
  16. {
  17. string[] inputTokens =
  18. input.Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
  19.  
  20. string key = inputTokens[0];
  21. string value = inputTokens[1];
  22.  
  23. if (dic.ContainsKey(key))
  24. {
  25. dic[key] = value;
  26. }
  27. else
  28. {
  29. dic.Add(key, value);
  30. }
  31.  
  32.  
  33.  
  34. input = Console.ReadLine();
  35. }
  36.  
  37. string defaultValue = Console.ReadLine();
  38.  
  39.  
  40. foreach (var item in dic)
  41. {
  42. if (item.Value == "null")
  43. {
  44. dic2.Add(item.Key, defaultValue);
  45. }
  46. else
  47. {
  48. dic2.Add(item.Key, item.Value);
  49. }
  50.  
  51. }
  52. foreach (var item in dic2.Where(x=> x.Value != defaultValue).OrderByDescending(x=> x.Value.Length))
  53. {
  54. Console.WriteLine($"{item.Key} <-> {item.Value}");
  55. }
  56. foreach (var item in dic2.Where(x=> x.Value == defaultValue))
  57. {
  58. Console.WriteLine($"{item.Key} <-> {item.Value}");
  59. }
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement