Advertisement
Vladimir76

Use Your Chains, Buddy

Feb 18th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace Use_Your_Chains_Buddy
  9. {
  10.     class Program
  11.     {
  12.         static void Main()
  13.         {
  14.             string htmlText = Console.ReadLine();
  15.             string pattern = @"<\s*p\s*>(.*?)<\s*\/p\s*>";
  16.             string patternLetterAndDigit = "[^a-z0-9\n]{2,}";
  17.             string patternParagraph = @"[^<p>\/]+";
  18.             List<string> text = new List<string>();
  19.             List<char> alphabet = new List<char>();
  20.             StringBuilder sb = new StringBuilder();
  21.            
  22.             MatchCollection matches = Regex.Matches(htmlText, pattern);
  23.             foreach (Match match in matches)
  24.             {
  25.                 string currentMatchStr = match.ToString();
  26.                 Match currentMatch = Regex.Match(currentMatchStr, patternParagraph);
  27.                 string currentText = currentMatch.ToString();
  28.                 string result = Regex.Replace(currentText, patternLetterAndDigit, " ");
  29.                 text.Add(result);
  30.             }
  31.  
  32.             for (char i = 'a'; i <= 'z'; i++)
  33.             {
  34.                 alphabet.Add(i);
  35.             }
  36.             int convertIndex;
  37.             string currentString = null;
  38.             for (int i = 0; i < text.Count; i++)
  39.             {
  40.                 currentString = text[i];
  41.                 for (int j = 0; j < currentString.Length; j++)
  42.                 {
  43.                     if (char.IsLetter(currentString[j]))
  44.                     {
  45.                         int indexLetter = alphabet.IndexOf(currentString[j]);
  46.                         if (indexLetter < 13)
  47.                         {
  48.                             convertIndex = indexLetter + 13;
  49.                             sb.Append(alphabet[convertIndex]);
  50.                         }
  51.                         else
  52.                         {
  53.                             convertIndex = indexLetter - 13;
  54.                             sb.Append(alphabet[convertIndex]);
  55.                         }
  56.                     }
  57.                     else
  58.                     {
  59.                         sb.Append(currentString[j]);
  60.                     }
  61.                 }
  62.                
  63.             }
  64.             Console.WriteLine(sb);
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement