Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace QueryMess
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- List<string> output = new List<string>();
- Regex regexSpaces = new Regex(@"(%20|\+)+");
- string groupPattern = @"([^\?^&]+)=([^\?^&]+)";
- while (input != "END")
- {
- string cleared = regexSpaces.Replace(input, " ");
- MatchCollection matches = Regex.Matches(cleared, groupPattern);
- Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
- foreach (Match item in matches)
- {
- List<string> list = new List<string>();
- if (! dictionary.ContainsKey(item.Groups[1].Value.Trim(' ')))
- {
- list.Add(item.Groups[2].Value.Trim(' '));
- dictionary.Add(item.Groups[1].Value.Trim(' '), list);
- }
- else
- {
- dictionary[item.Groups[1].Value.Trim(' ')].Add(item.Groups[2].Value.Trim(' '));
- }
- }
- StringBuilder stringToPrint = new StringBuilder();
- foreach (var item in dictionary)
- {
- stringToPrint.Append($"{item.Key}=[{string.Join(", ", item.Value)}]");
- }
- output.Add(stringToPrint.ToString());
- input = Console.ReadLine();
- }
- for (int i = 0; i < output.Count; i++)
- {
- Console.WriteLine(output[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement