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;
- using System.Threading.Tasks;
- namespace QueryMess
- {
- public class QueryMess
- {
- public static void Main()
- {
- Regex validPair = new Regex(@"^(.*?=.*?)$");
- Regex spaces = new Regex(@"((\+|%20)(\+|%20)*)");
- Dictionary<string, List<string>> allQueries =
- new Dictionary<string, List<string>>();
- StringBuilder result = new StringBuilder();
- string inputLine = Console.ReadLine();
- while (inputLine != "END")
- {
- string[] queryInfo = inputLine
- .Split(new[] { '&', '?' }, StringSplitOptions.RemoveEmptyEntries);
- foreach (string pair in queryInfo)
- {
- if (!validPair.IsMatch(pair))
- {
- continue;
- }
- string[] pairInfo = pair.Split('=');
- string key = pairInfo[0];
- string value = pairInfo[1];
- key = spaces.Replace(key, " ").Trim();
- value = spaces.Replace(value, " ").Trim();
- if (!allQueries.ContainsKey(key))
- {
- allQueries.Add(key, new List<string>());
- }
- allQueries[key].Add(value);
- }
- foreach (KeyValuePair<string, List<string>> pair in allQueries)
- {
- result.Append($"{pair.Key}=[{string.Join(", ", pair.Value)}]");
- }
- result.Append("\r\n");
- allQueries.Clear();
- inputLine = Console.ReadLine();
- }
- Console.WriteLine(result.ToString().Trim('\r', '\n'));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement