Advertisement
iliqnvidenov

Untitled

Mar 30th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.04 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. class Program
  8. {
  9.     static void Main()
  10.     {
  11.         string text = Console.ReadLine();
  12.         string direction = Console.ReadLine();
  13.         if (text.Length == 1)
  14.         {
  15.             int lastNum = 0;
  16.             char currentChar = text[0];
  17.             int asciiCodeValue = currentChar;
  18.             int digitCounter = 0;
  19.             int asciiCode = asciiCodeValue;
  20.             while (asciiCode > 0)
  21.             {
  22.                 asciiCode /= 10;
  23.                 digitCounter++;
  24.             }
  25.             if (digitCounter == 2)
  26.             {
  27.                 lastNum = asciiCodeValue % 10;
  28.             }
  29.             else if (digitCounter == 3)
  30.             {
  31.                 lastNum = asciiCodeValue % 100;
  32.                 lastNum %= 10;
  33.             }
  34.             else
  35.             {
  36.                 lastNum = asciiCodeValue;
  37.             }
  38.             Console.WriteLine(lastNum);
  39.             return;
  40.         }
  41.         List<int> nums = new List<int>();
  42.         for (int i = 0; i < text.Length; i++)
  43.         {
  44.             int lastNum = 0;
  45.             char currentChar = text[i];
  46.             int asciiCodeValue = currentChar;
  47.             int digitCounter = 0;
  48.             int asciiCode = asciiCodeValue;
  49.             while (asciiCode > 0)
  50.             {
  51.                 asciiCode /= 10;
  52.                 digitCounter++;
  53.             }
  54.             if (digitCounter == 2)
  55.             {
  56.                 lastNum = asciiCodeValue % 10;
  57.             }
  58.             else if (digitCounter == 3)
  59.             {
  60.                 lastNum = asciiCodeValue % 100;
  61.                 lastNum %= 10;
  62.             }
  63.             else
  64.             {
  65.                 lastNum = asciiCodeValue;
  66.             }
  67.             nums.Add(lastNum);
  68.         }
  69.         List<int> result = new List<int>();
  70.         for (int i = 0; i < nums.Count; i++)
  71.         {
  72.             int currentNum = nums[i];
  73.             if (currentNum % 2 == 0)
  74.             {
  75.                 currentNum *= currentNum;
  76.                 int countDigits = 0;
  77.                 int uselessNum = currentNum;
  78.                 if (currentNum == 10)
  79.                 {
  80.                     result.Add(1);
  81.                     result.Add(0);
  82.                 }
  83.                 else
  84.                 {
  85.                     while (uselessNum > 0)
  86.                     {
  87.                         uselessNum /= 10;
  88.                         countDigits++;
  89.                     }
  90.                     if (countDigits == 1)
  91.                     {
  92.                         result.Add(currentNum);
  93.                     }
  94.                     else if (countDigits == 2)
  95.                     {
  96.                         result.Add(currentNum / 10);
  97.                         result.Add(currentNum % 10);
  98.                     }
  99.                     else if (countDigits == 0)
  100.                     {
  101.                         result.Add(0);
  102.                     }
  103.                 }
  104.             }
  105.             else
  106.             {
  107.                 if (i == 0)
  108.                 {
  109.                     currentNum += nums[i + 1];
  110.                 }
  111.                 else if (i == (nums.Count-1))
  112.                 {
  113.                     currentNum += nums[i - 1];
  114.                 }
  115.                 else
  116.                 {
  117.                     currentNum += nums[i + 1];
  118.                     currentNum += nums[i - 1];
  119.                 }
  120.                 int countDigits = 0;
  121.                 int uselessNum = currentNum;
  122.                 if (currentNum == 10)
  123.                 {
  124.                     result.Add(1);
  125.                     result.Add(0);
  126.                 }
  127.                 else
  128.                 {
  129.                     while (uselessNum > 0)
  130.                     {
  131.                         uselessNum /= 10;
  132.                         countDigits++;
  133.                     }
  134.                     if (countDigits == 1)
  135.                     {
  136.                         result.Add(currentNum);
  137.                     }
  138.                     else if (countDigits == 2)
  139.                     {
  140.                         result.Add(currentNum / 10);
  141.                         result.Add(currentNum % 10);
  142.                     }
  143.                     else if (countDigits == 0)
  144.                     {
  145.                         result.Add(0);
  146.                     }
  147.                 }
  148.             }
  149.         }
  150.         int[,] matrix = new int[result.Count, result.Count];
  151.         if (direction == "\\")
  152.         {
  153.             for (int i = 0; i < result.Count; i++)
  154.             {
  155.                 matrix[i, i] = result[i];
  156.             }
  157.         }
  158.         else
  159.         {
  160.             for (int i = 0,j = result.Count-1; i < result.Count; i++,j--)
  161.             {
  162.                 matrix[i, j] = result[j];
  163.             }
  164.         }
  165.         for (int i = 0; i < result.Count; i++)
  166.         {
  167.             for (int j = 0; j < result.Count; j++)
  168.             {
  169.                 Console.Write("{0} ",matrix[i,j]);
  170.             }
  171.             Console.WriteLine();
  172.         }
  173.     }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement