Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- class P03TextTransformer
- {
- static StringBuilder output = new StringBuilder();
- static void Main()
- {
- string inputLine = Console.ReadLine();
- StringBuilder text = new StringBuilder();
- while (!inputLine.ToLower().Equals("burp"))
- {
- text.Append(inputLine);
- inputLine = Console.ReadLine();
- }
- string textNoSpaces = Regex.Replace(text.ToString(), @"\s+", " ");
- string pattern = @"(\$[^$%&']+\$)|(\%[^$%&']+\%)|(\&[^$%&']+\&)|(\'[^$%&']+\')";
- Regex regex = new Regex(pattern);
- Match match = regex.Match(textNoSpaces);
- while (match.ToString() != "")
- {
- string currWord = match.ToString();
- switch (match.ToString()[0])
- {
- case '$':
- DecodeChar(currWord, 1);
- break;
- case '%':
- DecodeChar(currWord, 2);
- break;
- case '&':
- DecodeChar(currWord, 3);
- break;
- case '\'':
- DecodeChar(currWord, 4);
- break;
- }
- output.Append(" ");
- match = match.NextMatch();
- }
- Console.WriteLine(output.ToString());
- }
- static StringBuilder DecodeChar(string currWord, int weight)
- {
- for (int i = 1; i < currWord.Length - 1; i++)
- {
- if (i % 2 != 0)
- {
- output.Append((char)(currWord[i] + weight));
- }
- else
- {
- output.Append((char)(currWord[i] - weight));
- }
- }
- return output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement