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.RegularExpressions;
- using System.Text;
- class Problem3
- {
- static void Main()
- {
- string input = Console.ReadLine();
- StringBuilder sb = new StringBuilder();
- while (input != "burp")
- {
- sb.Append(input);
- input = Console.ReadLine();
- }
- input = sb.ToString();
- input = Regex.Replace(input, @"\s{2,}", " ");
- string pattern = @"([$%&'])([^$%&']+?)\1";
- MatchCollection matches = Regex.Matches(input, pattern);
- StringBuilder result = new StringBuilder();
- foreach (Match item in matches)
- {
- int weight = DetermineWeight(item.Groups[1].Value);
- string captured = item.Groups[2].Value;
- for (int i = 0; i < captured.Count(); i++)
- {
- if (i%2==0)
- {
- result.Append((char)(captured[i] + weight));
- }
- else
- {
- result.Append((char)(captured[i] - weight));
- }
- }
- result.Append(" ");
- }
- result.Remove(result.Length - 1, 1);
- Console.WriteLine(result);
- }
- private static int DetermineWeight(string special)
- {
- switch (special)
- {
- case "$": return 1;
- case "%": return 2;
- case "&": return 3;
- case "'": return 4;
- default: return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement