BubaLazi

LinqLambda01Proba

Aug 10th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 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 MultiDictionaries
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             Dictionary<string, string> words = new Dictionary<string, string>();
  14.             string[] input = Console.ReadLine().Split(new char[] { ' ','-','>' },
  15.                 StringSplitOptions.RemoveEmptyEntries);
  16.            
  17.             Dictionary<string, string> replaced = new Dictionary<string, string>();
  18.  
  19.             while (input[0] != "end")
  20.             {
  21.                 string wordsKey = input[0];
  22.                 string wordsValue = input[1];
  23.                 words.Add(wordsKey, wordsValue);
  24.             }
  25.  
  26.             string defaultValue = Console.ReadLine();
  27.  
  28.             foreach(KeyValuePair<string, string> removed in words)
  29.             {
  30.                 string toRemove = "null";
  31.                 if (!words.ContainsValue(toRemove))
  32.                 {
  33.                     replaced[removed.Key] = defaultValue;
  34.                     words.Remove(removed.Key);  
  35.                 }
  36.  
  37.                 replaced = replaced.OrderByDescending(pair => pair.Value).
  38.                     ToDictionary(pair => pair.Key,pair => pair.Value);
  39.  
  40.                 Console.WriteLine("{words.Key} -> {words.Value}");
  41.                 Console.WriteLine("{replaced.Key} -> {replaced.Value}");
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment