JulianJulianov

Deciphering

Jul 4th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  1. Deciphering
  2. Now that Gencho has filled his dictionary, he starts deciphering the old books to find in which one the relics and their locations are documented.
  3. You will receive two lines. The first one will have an encrypted string, which you will have to decode. On the second line you will receive two letters or substrings, separated by a single space.
  4. First you will have to decode the first line by reducing the ASCII value of each character in it by 3. Then you should get the two substrings of the second line. You must find every occurrence of the first substring in the now decrypted text and replace it with the second substring.
  5. Also, you don't know which book you have taken, so you must check if it is valid. A valid text contains only lowercase letters, from 'd' onwards, and the symbols '{', '}', '|', '#'. If the text is invalid, you should not try to decipher it and you should print "This is not the book you are looking for.".
  6. Input
  7. Two lines, one with text to decipher and one with two substrings to replace in the text.
  8. Output
  9. One line with the deciphered text.
  10. Examples
  11. Input
  12. wkhfn#|rx#jhqfkr#phf#exw#|rxu#uholf#lv#khfgohg#lq#hfrwkhu#sohfhw
  13. ec an
  14. Output
  15. thank you gencho man but your relic is handled in another planet
  16.  
  17. Input
  18. arx#vkdww#qrw#sdvv
  19. t l
  20. Output
  21. This is not the book you are looking for.
  22.  
  23. using System;
  24.  
  25. public class Program
  26. {
  27.     public static void Main()
  28.     {
  29.          var encryptedString = Console.ReadLine();
  30.          var twoLettersOrSubstrings = Console.ReadLine().Split();
  31.  
  32.          var decryptedString = "";
  33.          foreach (var symbol in encryptedString)
  34.          {
  35.              if (symbol < 100 || symbol > 125)// От 'd' = 100; до '}' = 125;
  36.              {
  37.                  if (symbol == 35)// '#' = 35;
  38.                  {
  39.                      decryptedString += (char)(symbol - 3);
  40.                      continue;
  41.                  }
  42.                  Console.WriteLine("This is not the book you are looking for.");
  43.                  return;
  44.              }
  45.              decryptedString += (char)(symbol - 3);
  46.          }
  47.          while (decryptedString.Contains(twoLettersOrSubstrings[0]))
  48.          {
  49.              decryptedString = decryptedString.Replace(twoLettersOrSubstrings[0], twoLettersOrSubstrings[1]);  
  50.          }
  51.          Console.WriteLine(decryptedString);
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment