koksibg

Detective Boev

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