Advertisement
Guest User

Untitled

a guest
Jun 1st, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4. class P03TextTransformer
  5. {
  6.     static StringBuilder output = new StringBuilder();
  7.     static void Main()
  8.     {
  9.         string inputLine = Console.ReadLine();
  10.         StringBuilder text = new StringBuilder();
  11.  
  12.         while (!inputLine.ToLower().Equals("burp"))
  13.         {
  14.             text.Append(inputLine);
  15.             inputLine = Console.ReadLine();
  16.         }
  17.  
  18.         string textNoSpaces = Regex.Replace(text.ToString(), @"\s+", " ");
  19.  
  20.         string pattern = @"(\$[^$%&']+\$)|(\%[^$%&']+\%)|(\&[^$%&']+\&)|(\'[^$%&']+\')";
  21.         Regex regex = new Regex(pattern);
  22.         Match match = regex.Match(textNoSpaces);
  23.  
  24.         while (match.ToString() != "")
  25.         {
  26.             string currWord = match.ToString();
  27.             switch (match.ToString()[0])
  28.             {
  29.                 case '$':
  30.                     DecodeChar(currWord, 1);
  31.                     break;
  32.                 case '%':
  33.                     DecodeChar(currWord, 2);
  34.                     break;
  35.                 case '&':
  36.                     DecodeChar(currWord, 3);
  37.                     break;
  38.                 case '\'':
  39.                     DecodeChar(currWord, 4);
  40.                     break;
  41.             }
  42.             output.Append(" ");
  43.             match = match.NextMatch();
  44.         }
  45.  
  46.         Console.WriteLine(output.ToString());
  47.     }
  48.  
  49.     static StringBuilder DecodeChar(string currWord, int weight)
  50.     {
  51.         for (int i = 1; i < currWord.Length - 1; i++)
  52.         {
  53.             if (i % 2 != 0)
  54.             {
  55.                 output.Append((char)(currWord[i] + weight));
  56.             }
  57.             else
  58.             {
  59.                 output.Append((char)(currWord[i] - weight));
  60.             }
  61.         }
  62.  
  63.         return output;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement