SHARE
TWEET

Untitled

a guest Jun 1st, 2015 28 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Text;
  6.  
  7. class Problem3
  8. {
  9.     static void Main()
  10.     {
  11.         string input = Console.ReadLine();
  12.         StringBuilder sb = new StringBuilder();
  13.         while (input != "burp")
  14.         {
  15.             sb.Append(input);
  16.             input = Console.ReadLine();
  17.         }
  18.         input = sb.ToString();
  19.         input = Regex.Replace(input, @"\s{2,}", " ");
  20.         string pattern = @"([$%&'])([^$%&']+?)\1";
  21.         MatchCollection matches = Regex.Matches(input, pattern);
  22.         StringBuilder result = new StringBuilder();
  23.         foreach (Match item in matches)
  24.         {
  25.             int weight = DetermineWeight(item.Groups[1].Value);
  26.             string captured = item.Groups[2].Value;
  27.             for (int i = 0; i < captured.Count(); i++)
  28.             {
  29.                 if (i%2==0)
  30.                 {
  31.                     result.Append((char)(captured[i] + weight));
  32.                 }
  33.                 else
  34.                 {
  35.                     result.Append((char)(captured[i] - weight));
  36.                 }
  37.             }
  38.             result.Append(" ");
  39.         }
  40.         result.Remove(result.Length - 1, 1);
  41.         Console.WriteLine(result);
  42.     }
  43.  
  44.     private static int DetermineWeight(string special)
  45.     {
  46.         switch (special)
  47.         {
  48.             case "$": return 1;
  49.             case "%": return 2;
  50.             case "&": return 3;
  51.             case "'": return 4;
  52.             default: return 0;
  53.         }
  54.     }
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top