WindFell

Use Your Chains Buddy

Mar 13th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. class UseYourChainsBuddy
  8. {
  9.     static void Main(string[] args)
  10.     {
  11.         int bufSize = 8192;
  12.         Stream inStream = Console.OpenStandardInput(bufSize);
  13.         Console.SetIn(new StreamReader(inStream, Console.InputEncoding, false, bufSize));
  14.  
  15.         string input = Console.ReadLine();
  16.  
  17.         string pattern = @"<p>(.*?)<\/p>"; //tried this too same result @"(?<=<p>)(.*?)<?=<\/p>)"
  18.         string[] words = Regex.Matches(input, pattern)
  19.             .Cast<Match>()
  20.             .Select(m => m.Groups[1].Value) //m.Value with the old regex above
  21.             .ToArray();
  22.  
  23.         for (int word = 0; word < words.Length; word++)
  24.         {
  25.             words[word] = Regex.Replace(words[word], @"[^a-z\d]+", " ");
  26.  
  27.             StringBuilder builder = new StringBuilder();
  28.  
  29.             for (int letter = 0; letter < words[word].Length; letter++)
  30.             {
  31.                 if (words[word][letter] >= 'a' && words[word][letter] <= 'm')
  32.                 {
  33.                     builder.Append((char)(words[word][letter] + 13));
  34.                 }
  35.                 else if (words[word][letter] >= 'n' && words[word][letter] <= 'z')
  36.                 {
  37.                     builder.Append((char)(words[word][letter] - 13));
  38.                 }
  39.                 else
  40.                 {
  41.                     builder.Append(words[word][letter]);
  42.                 }
  43.             }
  44.  
  45.             words[word] = builder.ToString();
  46.         }
  47.  
  48.         string output = string.Join(" ", words);
  49.  
  50.         output = Regex.Replace(output, @"\s+|\n+", " ");
  51.         Console.WriteLine(output);
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment