Advertisement
enevlogiev

Untitled

Aug 28th, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 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 EncryptedMatrix
  8. {
  9.     class EncryptedMatrix
  10.     {
  11.         static void Main()
  12.         {
  13.             string message = Console.ReadLine();
  14.             string direction = Console.ReadLine();
  15.  
  16.             string convertedMessage = "0";
  17.             foreach (char ch in message.ToCharArray())
  18.             {
  19.                 int lastDigit = ch % 10;
  20.                 convertedMessage += lastDigit;
  21.             }
  22.             convertedMessage += "0";
  23.            
  24.             string encryptedMessage = "";
  25.             for (int i = 1; i < convertedMessage.Length - 1; i++)
  26.             {
  27.                 int digit = convertedMessage[i] - '0';
  28.                 if (digit % 2 == 0)
  29.                 {
  30.                     encryptedMessage += digit * digit;
  31.                 }
  32.                 else
  33.                 {
  34.                     encryptedMessage += digit + convertedMessage[i - 1] - '0' + convertedMessage[i + 1] - '0';
  35.                 }
  36.             }
  37.  
  38.             int len = encryptedMessage.Length;
  39.  
  40.             int[,] matrix = new int[len, len];
  41.             if (direction == "\\")
  42.             {
  43.                 for (int i = 0; i < len; i++)
  44.                 {
  45.                     matrix[i, i] = encryptedMessage[i] - '0';
  46.                 }
  47.             }
  48.             else
  49.             {
  50.                 for (int i = 0; i < len; i++)
  51.                 {
  52.                     matrix[len - 1 - i, i] = encryptedMessage[i] - '0';
  53.                 }
  54.             }
  55.  
  56.             for (int i = 0; i < len; i++)
  57.             {
  58.                 for (int j = 0; j < len; j++)
  59.                 {
  60.                     Console.Write(matrix[i,j] + " ");
  61.                 }
  62.                 Console.WriteLine();
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement