Advertisement
dimipan80

Use Your Chains, Buddy

May 14th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. /* As input will receive an HTML document as a single string. You need to get the text from all the <p> tags and replace all characters which are not small letters and numbers with a space ' '. After that you must decrypt the text - all letters from a to m are converted to letters from n to z accordingly (a -> n, b -> o, ... m -> z). The letters from n to z are converted to letters from a to m accordingly (n -> a, o -> b, ... z -> m). All multiple spaces should then be replaced by only one space! Print at a single line the decrypted text.*/
  2.  
  3. namespace _08.UseYourChainsBuddy
  4. {
  5.     using System;
  6.     using System.Linq;
  7.     using System.Text;
  8.     using System.Text.RegularExpressions;
  9.  
  10.     class UseYourChainsBuddy
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string text = Console.ReadLine();
  15.             const string pattern = @"<p>(.+?)<\/p>";
  16.  
  17.             MatchCollection matches = Regex.Matches(text, pattern);
  18.             foreach (StringBuilder sb in from Match match in matches select new StringBuilder(match.Groups[1].Value))
  19.             {
  20.                 for (int i = 0; i < sb.Length; i++)
  21.                 {
  22.                     char symb = sb[i];
  23.                     if ((char.IsLetter(symb) && char.IsLower(symb)) || char.IsDigit(symb))
  24.                     {
  25.                         if (!char.IsLower(symb)) continue;
  26.                         int asciiCode = symb;
  27.                         asciiCode += (symb < 110) ? 13 : -13;
  28.                         sb[i] = (char)asciiCode;
  29.                     }
  30.                     else
  31.                     {
  32.                         sb[i] = ' ';
  33.                     }
  34.                 }
  35.  
  36.                 Regex rgx = new Regex(@"\s+");
  37.                 Console.Write(rgx.Replace(sb.ToString(), " "));
  38.             }
  39.             Console.WriteLine();
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement