Advertisement
ViktorMarinov

02.Detective Boev

Jul 14th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 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.  
  7. class DetectiveBoev
  8. {
  9.     static void Main()
  10.     {
  11.         string secretWord = Console.ReadLine();
  12.         string message = Console.ReadLine();
  13.  
  14.         int sum = 0;
  15.         for (int i = 0; i < secretWord.Length; i++)
  16.         {
  17.             sum += (int)secretWord[i];
  18.         }
  19.  
  20.         while (sum /10 != 0)
  21.         {
  22.             int newSum = 0;
  23.             while (sum > 0)
  24.             {
  25.                 newSum += sum % 10;
  26.                 sum /= 10;
  27.             }
  28.             sum = newSum;
  29.         }
  30.         StringBuilder str = new StringBuilder(message);
  31.         for (int i = 0; i < str.Length; i++)
  32.         {
  33.             if (str[i] % sum == 0)
  34.             {
  35.                 str[i] = (char)((int)str[i] + sum);
  36.             }
  37.             else
  38.             {
  39.                 str[i] = (char)((int)str[i] - sum);
  40.             }
  41.         }
  42.         message = str.ToString();
  43.         char[] arr = message.ToCharArray();
  44.         Array.Reverse(arr);
  45.         Console.WriteLine(new string(arr));
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement