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;
- using System.Threading.Tasks;
- namespace QueryMess
- {
- class QueryMess
- {
- static void Main(string[] args)
- {
- Dictionary<int, Dictionary<string, List<string>>> info =
- new Dictionary<int, Dictionary<string, List<string>>>();
- string inputLine = Console.ReadLine();
- int dicCounter = 0;
- while (!inputLine.Equals("END"))
- {
- info[dicCounter] = new Dictionary<string, List<string>>();
- string[] splittedInput = inputLine.
- Split(new char[] { '&' , '?'}, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string key = string.Empty;
- string value = string.Empty;
- foreach (string input in splittedInput)
- {
- if (Regex.IsMatch(input, @"(.*?)=(.*)"))
- {
- Match match = Regex.Match(input, @"(.*?)=(.*)");
- key = match.Groups[1].ToString();
- value = match.Groups[2].ToString();
- key = Regex.Replace(key, @"((%20*\+*)|(\+))+", "");
- key = Regex.Replace(key, @"\s*", "");
- value = Regex.Replace(value, @"((%20*\+*)|(\+))+", " ");
- value = Regex.Replace(value, @"\s+", " ");
- value = value.Trim();
- if (!info[dicCounter].ContainsKey(key))
- {
- info[dicCounter].Add(key, new List<string>());
- info[dicCounter][key].Add(value);
- }
- else
- {
- info[dicCounter][key].Add(value);
- }
- }
- }
- inputLine = Console.ReadLine();
- dicCounter++;
- }
- foreach (int currLine in info.Keys)
- {
- foreach (KeyValuePair<string, List<string>> pair in info[currLine])
- {
- Console.Write($"{pair.Key}=[{string.Join(", ", pair.Value)}]");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment