Advertisement
4valeri

Detective Boev

Feb 3rd, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2.  
  3. class DetectiveBoev
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         string secretWord = Console.ReadLine();
  8.         int sum = 0;
  9.         string encryptedMessage = Console.ReadLine();
  10.  
  11.         for (int i = 0; i < secretWord.Length; i++)
  12.         {
  13.             char symbol = secretWord[i];
  14.             sum += symbol;
  15.         }
  16.  
  17.         while (sum > 9)
  18.         {
  19.             int mask = 0;
  20.             while (sum != 0)
  21.             {
  22.                 mask += sum % 10;
  23.                 sum /= 10;
  24.             }
  25.             sum = mask;
  26.         }
  27.         char[] message = encryptedMessage.ToCharArray();
  28.  
  29.         for (int i = 0; i < message.Length; i++)
  30.         {
  31.             char symbol = message[i];
  32.  
  33.             if (symbol % sum == 0)
  34.             {
  35.                 symbol += (char)sum;
  36.             }
  37.             else
  38.             {
  39.                 symbol -= (char)sum;
  40.             }
  41.             message[i] = symbol;
  42.  
  43.             }
  44.  
  45.             Array.Reverse(message);
  46.  
  47.         string output = new string(message);
  48.         Console.WriteLine(output);
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement