Advertisement
WindFell

Use Your Chains Buddy

Mar 13th, 2018
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 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[] paragraphs = 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 paragraph = 0; paragraph < paragraphs.Length; paragraph++)
  24.         {
  25.             paragraphs[paragraph] = Regex.Replace(paragraphs[paragraph], @"[^a-z\d]+", " ");
  26.  
  27.             StringBuilder builder = new StringBuilder();
  28.  
  29.             for (int symbol = 0; symbol < paragraphs[paragraph].Length; symbol++)
  30.             {
  31.                 if (paragraphs[paragraph][symbol] >= 'a' && paragraphs[paragraph][symbol] <= 'm')
  32.                 {
  33.                     builder.Append((char)(paragraphs[paragraph][symbol] + 13));
  34.                 }
  35.                 else if (paragraphs[paragraph][symbol] >= 'n' && paragraphs[paragraph][symbol] <= 'z')
  36.                 {
  37.                     builder.Append((char)(paragraphs[paragraph][symbol] - 13));
  38.                 }
  39.                 else
  40.                 {
  41.                     builder.Append(paragraphs[paragraph][symbol]);
  42.                 }
  43.             }
  44.  
  45.             paragraphs[paragraph] = builder.ToString();
  46.         }
  47.  
  48.         string output = string.Join(" ", paragraphs);
  49.  
  50.         output = Regex.Replace(output, @"\s+|\n+", " ");
  51.         Console.WriteLine(output);
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement