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;
- class Program
- {
- static void Main()
- {
- string text = Console.ReadLine();
- string direction = Console.ReadLine();
- if (text.Length == 1)
- {
- int lastNum = 0;
- char currentChar = text[0];
- int asciiCodeValue = currentChar;
- int digitCounter = 0;
- int asciiCode = asciiCodeValue;
- while (asciiCode > 0)
- {
- asciiCode /= 10;
- digitCounter++;
- }
- if (digitCounter == 2)
- {
- lastNum = asciiCodeValue % 10;
- }
- else if (digitCounter == 3)
- {
- lastNum = asciiCodeValue % 100;
- lastNum %= 10;
- }
- else
- {
- lastNum = asciiCodeValue;
- }
- Console.WriteLine(lastNum);
- return;
- }
- List<int> nums = new List<int>();
- for (int i = 0; i < text.Length; i++)
- {
- int lastNum = 0;
- char currentChar = text[i];
- int asciiCodeValue = currentChar;
- int digitCounter = 0;
- int asciiCode = asciiCodeValue;
- while (asciiCode > 0)
- {
- asciiCode /= 10;
- digitCounter++;
- }
- if (digitCounter == 2)
- {
- lastNum = asciiCodeValue % 10;
- }
- else if (digitCounter == 3)
- {
- lastNum = asciiCodeValue % 100;
- lastNum %= 10;
- }
- else
- {
- lastNum = asciiCodeValue;
- }
- nums.Add(lastNum);
- }
- List<int> result = new List<int>();
- for (int i = 0; i < nums.Count; i++)
- {
- int currentNum = nums[i];
- if (currentNum % 2 == 0)
- {
- currentNum *= currentNum;
- int countDigits = 0;
- int uselessNum = currentNum;
- if (currentNum == 10)
- {
- result.Add(1);
- result.Add(0);
- }
- else
- {
- while (uselessNum > 0)
- {
- uselessNum /= 10;
- countDigits++;
- }
- if (countDigits == 1)
- {
- result.Add(currentNum);
- }
- else if (countDigits == 2)
- {
- result.Add(currentNum / 10);
- result.Add(currentNum % 10);
- }
- else if (countDigits == 0)
- {
- result.Add(0);
- }
- }
- }
- else
- {
- if (i == 0)
- {
- currentNum += nums[i + 1];
- }
- else if (i == (nums.Count-1))
- {
- currentNum += nums[i - 1];
- }
- else
- {
- currentNum += nums[i + 1];
- currentNum += nums[i - 1];
- }
- int countDigits = 0;
- int uselessNum = currentNum;
- if (currentNum == 10)
- {
- result.Add(1);
- result.Add(0);
- }
- else
- {
- while (uselessNum > 0)
- {
- uselessNum /= 10;
- countDigits++;
- }
- if (countDigits == 1)
- {
- result.Add(currentNum);
- }
- else if (countDigits == 2)
- {
- result.Add(currentNum / 10);
- result.Add(currentNum % 10);
- }
- else if (countDigits == 0)
- {
- result.Add(0);
- }
- }
- }
- }
- int[,] matrix = new int[result.Count, result.Count];
- if (direction == "\\")
- {
- for (int i = 0; i < result.Count; i++)
- {
- matrix[i, i] = result[i];
- }
- }
- else
- {
- for (int i = 0,j = result.Count-1; i < result.Count; i++,j--)
- {
- matrix[i, j] = result[j];
- }
- }
- for (int i = 0; i < result.Count; i++)
- {
- for (int j = 0; j < result.Count; j++)
- {
- Console.Write("{0} ",matrix[i,j]);
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement