Advertisement
darighteous1

04. EncryptedMatrix

Mar 31st, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.88 KB | None | 0 0
  1. using System;
  2.  
  3. class EncryptedMatrix
  4. {
  5.     static void Main()
  6.     {
  7.         string input = Console.ReadLine();
  8.         string direction = Console.ReadLine();
  9.  
  10.         string conversion = String.Empty;
  11.  
  12.         for (int i = 0; i < input.Length; i++)
  13.         {
  14.             conversion += (input[i] % 10);
  15.         }
  16.  
  17.         string encryption = String.Empty;
  18.         for (int i = 0; i < conversion.Length; i++)
  19.         {
  20.             if (conversion.Length == 1)
  21.             {
  22.                 int currentDigit = int.Parse(conversion[i].ToString());
  23.                 if (currentDigit%2==0)
  24.                 {
  25.                     encryption += currentDigit * currentDigit;
  26.                     break;
  27.                 }
  28.                 else
  29.                 {
  30.                     encryption += currentDigit;
  31.                     break;
  32.                 }
  33.             }
  34.             if (i == 0 || i == conversion.Length - 1)
  35.             {
  36.                 int currentDigit = int.Parse(conversion[i].ToString());
  37.                 if (currentDigit % 2 == 0)
  38.                 {
  39.                     encryption += currentDigit * currentDigit;
  40.                 }
  41.                 else
  42.                 {
  43.                     int kucataCifra = int.Parse(conversion[i - 1 > 0 ? i - 1 : i + 1].ToString());
  44.                     encryption += (currentDigit + kucataCifra);
  45.                 }
  46.             }
  47.             else
  48.             {
  49.                 int currentDigit = int.Parse(conversion[i].ToString());
  50.                 if (currentDigit % 2 == 0)
  51.                 {
  52.                     encryption += (currentDigit * currentDigit);
  53.                 }
  54.                 else
  55.                 {
  56.                     int leftDigit = int.Parse(conversion[i - 1].ToString());
  57.                     int rightDigit = int.Parse(conversion[i + 1].ToString());
  58.                     encryption += (currentDigit + leftDigit + rightDigit);
  59.                 }
  60.             }
  61.         }
  62.  
  63.         int n = encryption.Length;
  64.         int[,] matrix = new int[n, n];
  65.  
  66.  
  67.         if (direction == "\\")
  68.         {
  69.             for (int i = 0; i < matrix.GetLength(0); i++)
  70.             {
  71.                 matrix[i, i] = int.Parse(encryption[i].ToString());
  72.             }
  73.  
  74.             for (int i = 0; i < n; i++)
  75.             {
  76.                 for (int j = 0; j < n; j++)
  77.                 {
  78.                     Console.Write("{0} ", matrix[i, j]);
  79.                 }
  80.                 Console.WriteLine();
  81.             }
  82.         }
  83.  
  84.         if (direction == "/")
  85.         {
  86.             int col = 0;
  87.             for (int i = n - 1; i >= 0; i--)
  88.             {
  89.                 matrix[col, i] = int.Parse(encryption[i].ToString());
  90.                 col++;
  91.             }
  92.             for (int i = 0; i < n; i++)
  93.             {
  94.                 for (int j = 0; j < n; j++)
  95.                 {
  96.                     Console.Write("{0} ", matrix[i, j]);
  97.                 }
  98.                 Console.WriteLine();
  99.             }
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement