Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Problem_4
- {
- class Program
- {
- static void Main(string[] args)
- {
- string msg = Console.ReadLine();
- char dir = char.Parse(Console.ReadLine());
- string number = convertToNumber(msg);
- string num = "";
- int firstDigit = Convert.ToInt32(new string(number[0], 1));
- int lastDigit = 0;
- int secondDigit = 0;
- int beforeLastDigit = 0;
- if (convertToNumber(msg).Length > 1)
- {
- lastDigit = Convert.ToInt32(new string(number[number.Length - 1], 1));
- secondDigit = Convert.ToInt32(new string(number[1], 1));
- beforeLastDigit = Convert.ToInt32(new string(number[number.Length - 2], 1));
- }
- if (firstDigit == 0 || firstDigit % 2 == 0)
- {
- firstDigit = firstDigit * firstDigit;
- }
- if (firstDigit % 2 != 0)
- {
- firstDigit = firstDigit + 0 + secondDigit;
- }
- if (lastDigit == 0 || lastDigit % 2 == 0)
- {
- lastDigit = lastDigit * lastDigit;
- }
- if (lastDigit % 2 != 0)
- {
- lastDigit = lastDigit + 0 + beforeLastDigit;
- }
- num += firstDigit;
- for (int i = 1; i < number.Length - 1; i++)
- {
- int digit = Convert.ToInt32(new string(number[i], 1));
- int beforeDigit = Convert.ToInt32(new string(number[i - 1], 1));
- int afterDigit = Convert.ToInt32(new string(number[i + 1], 1));
- if (digit == 0 || digit % 2 == 0)
- {
- digit = digit * digit;
- }
- if (digit % 2 != 0)
- {
- digit = digit + beforeDigit + afterDigit;
- }
- num += digit;
- }
- num += lastDigit;
- int len = num.Length;
- char[,] matrix = new char[len, len];
- int count = 0;
- for (int i = 0; i < len; i++)
- {
- for (int j = 0; j < len; j++)
- {
- matrix[i, j] = '0';
- }
- }
- if (dir == '\\')
- {
- for (int i = 0; i < len; i++)
- {
- for (int j = 0; j < len; j++)
- {
- matrix[i, count] = num[count];
- }
- count++;
- }
- }
- else
- {
- for (int i = len - 1; i >= 0; i--)
- {
- for (int j = 0; j < len; j++)
- {
- matrix[i, count] = num[count];
- }
- count++;
- }
- }
- if (convertToNumber(msg).Length == 1)
- {
- Console.WriteLine(convertToNumber(msg));
- }
- else
- {
- for (int i = 0; i < len; i++)
- {
- for (int j = 0; j < len; j++)
- {
- Console.Write(matrix[i, j] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- static string convertToNumber(string msg)
- {
- string output = "";
- for (int i = 0; i < msg.Length; i++)
- {
- int last = getValue(msg[i]) % 10;
- output += last;
- }
- return output;
- }
- static int getValue(char c)
- {
- return (int)c;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement