mellowdeep

Encrypted Matrix

Nov 6th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. class EM
  7. {
  8.     public static void Main()
  9.     {
  10.         string input = Console.ReadLine();
  11.         byte[] array = Encoding.ASCII.GetBytes(input);
  12.  
  13.         List<int> numbers = new List<int>();
  14.         foreach (char ch in array)
  15.         {
  16.             numbers.Add(ch % 10);
  17.  
  18.         }
  19.  
  20.         List<int> cryptedNumbers = new List<int>();
  21.         for (int i = 0; i < numbers.Count; i++)
  22.         {
  23.             int currentDigit = numbers[i];
  24.             int result;
  25.  
  26.             if (currentDigit % 2 == 0)
  27.             {
  28.                 result = currentDigit * currentDigit;
  29.  
  30.                 if (result >= 10)
  31.                 {
  32.                     cryptedNumbers.Add(result / 10);
  33.                     cryptedNumbers.Add(result % 10);
  34.                 }
  35.                 else
  36.                 {
  37.                     cryptedNumbers.Add(result);
  38.                 }
  39.             }
  40.             else
  41.             {
  42.                 int previousDigit = i == 0 ? 0 : numbers[i - 1];
  43.                 int nextDigit = i == numbers.Count - 1 ? 0 : numbers[i + 1];
  44.                 result = currentDigit + previousDigit + nextDigit;
  45.                 if (result >= 10)
  46.                 {
  47.                     cryptedNumbers.Add(result / 10);
  48.                     cryptedNumbers.Add(result % 10);
  49.                 }
  50.                 else
  51.                 {
  52.                     cryptedNumbers.Add(result);
  53.                 }
  54.             }
  55.         }
  56.         string diagonal = Console.ReadLine();
  57.         int position;
  58.         int update;
  59.  
  60.         if (diagonal == "\\")
  61.         {
  62.             position = 0;
  63.             update = 1;
  64.         }
  65.         else
  66.         {
  67.             position = cryptedNumbers.Count - 1;
  68.             update = -1;
  69.         }
  70.  
  71.         for (int i = 0; i < cryptedNumbers.Count; i++)
  72.         {
  73.             for (int j = 0; j < cryptedNumbers.Count; j++)
  74.             {
  75.                 if (j == position)
  76.                 {
  77.                     Console.Write(cryptedNumbers[position] + " ");
  78.                 }
  79.                 else
  80.                 {
  81.                     Console.Write("0 ");
  82.                 }
  83.             }
  84.  
  85.             Console.WriteLine();
  86.  
  87.             position += update;
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment