Advertisement
Aborigenius

CharEncoding

Jun 21st, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 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. namespace CharRotation
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string strInput = Console.ReadLine();
  14.             string intInput = Console.ReadLine();
  15.             int[] intArray = intInput.Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
  16.  
  17.             byte[] asciiInput = Encoding.ASCII.GetBytes(strInput).ToArray();
  18.             byte[] myResultArray = new byte[intArray.Length];
  19.             for ( byte i= 0, j =0; i < asciiInput.Length; i++, j++)
  20.             {
  21.                     if (intArray[j] % 2 == 0)
  22.                     {
  23.                         myResultArray[i] = (byte)(asciiInput[i] - intArray[j]);
  24.  
  25.                     }
  26.                     else
  27.                     {
  28.                         myResultArray[i] = (byte)(asciiInput[i] + intArray[j]);
  29.                     }
  30.             }
  31.  
  32.             string result = System.Text.Encoding.UTF8.GetString(myResultArray);
  33.             Console.WriteLine(result);
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement