Advertisement
Guest User

Untitled

a guest
May 19th, 2015
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5.  
  6. class QueryMes
  7. {
  8.     static void Main()
  9.     {
  10.         string input = Console.ReadLine();
  11.         string pattern = @"(?<key>\w+)=(?<value>\w+)";
  12.         Regex rgx = new Regex(pattern);
  13.  
  14.         while (input != "END")
  15.         {
  16.  
  17.             MatchCollection matches = rgx.Matches(input);
  18.             Dictionary<string, List<string>> results = new Dictionary<string, List<string>>();
  19.  
  20.             foreach (Match item in matches)
  21.             {
  22.                 if (!results.ContainsKey(item.Groups["key"].Value))
  23.                 {
  24.                     results.Add(item.Groups["key"].Value, new List<string>());
  25.                 }
  26.                 results[item.Groups["key"].Value].Add(item.Groups["value"].Value);
  27.             }
  28.  
  29.             foreach (var r in results)
  30.             {
  31.                 Console.Write("{0}=[{1}]", r.Key, string.Join(", ", r.Value));
  32.             }
  33.             Console.WriteLine();
  34.             input = Console.ReadLine();
  35.         }
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement