Aborigenius

DefaultValues

Aug 15th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace DefaultValues
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, string> values = new Dictionary<string, string>();
  14.             Dictionary<string, string> values2 = new Dictionary<string, string>();
  15.  
  16.             string input = Console.ReadLine();
  17.             while (input != "end")
  18.             {
  19.                 string[] inputTokens = input.Split(new string[] { " -> " },
  20.                     StringSplitOptions.RemoveEmptyEntries);
  21.                 string dictKey = inputTokens[0];
  22.                 string dictVal = inputTokens[1];
  23.  
  24.                 values[dictKey] = dictVal;
  25.  
  26.                 input = Console.ReadLine();
  27.             }
  28.             string endInput = Console.ReadLine();
  29.  
  30.             foreach (var record in values)
  31.             {
  32.                 if (record.Value == "null")
  33.                 {
  34.                     values2[record.Key] = endInput;
  35.                 }
  36.             }
  37.             values = values.Where(x => x.Value != "null")
  38.              .OrderByDescending(x => x.Value.Length)
  39.              .ToDictionary(x => x.Key, x => x.Value);
  40.             //   Console.WriteLine(string.Join("<->", values));
  41.             foreach (KeyValuePair<string, string> item in values)
  42.             {
  43.                                  Console.WriteLine("{0} <-> {1}", item.Key, item.Value);
  44.             }
  45.  
  46.             foreach (KeyValuePair<string, string> item in values2)
  47.             {
  48.                 Console.WriteLine("{0} <-> {1}", item.Key, item.Value);
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment