Created
May 27, 2015 21:55
-
-
Save Filkolev/1d438c246992d2f6e7ed to your computer and use it in GitHub Desktop.
Use Your Chains Buddy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
public class UseYourChainsBuddy | |
{ | |
public static void Main() | |
{ | |
const int characterOffset = 'n' - 'a'; | |
string input = Console.ReadLine(); | |
Regex symbolsPattern = new Regex(@"[^a-z0-9]+"); | |
Regex whitespacePattern = new Regex(@"\s+"); | |
var matches = Regex.Matches(input, @"<p>(.*?)<\/p>"); | |
StringBuilder result = new StringBuilder(); | |
foreach (Match match in matches) | |
{ | |
string currentEntry = match.Groups[1].ToString(); | |
currentEntry = symbolsPattern.Replace(currentEntry, " "); | |
currentEntry = whitespacePattern.Replace(currentEntry, " "); | |
foreach (var symbol in currentEntry) | |
{ | |
if ('a' <= symbol && symbol <= 'm') | |
{ | |
result.Append((char)(symbol + characterOffset)); | |
} | |
else if ('n' <= symbol && symbol <= 'z') | |
{ | |
result.Append((char)(symbol - characterOffset)); | |
} | |
else | |
{ | |
result.Append(symbol); | |
} | |
} | |
} | |
Console.WriteLine(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment