Advertisement
MattePRL

Ola Ola Aleksandra Aleksandra

Feb 23rd, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.71 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 OlaOlaOlaAleksandraMalomowna
  8. {
  9.     class Program
  10.     {
  11.         const bool IS_DEBUG = true;
  12.         const bool USE_SMALL_NUMBERS = true; // Random lubi wywalać różne smoki z siebie, lepiej go ograniczyć jeśli chcemy weryfikować działanie programu
  13.         const int SMALL_NUMBER_MAX = 9;
  14.  
  15.         static void Main(string[] args)
  16.         {
  17.             int arrSize = 0;
  18.             int ltrResult = 0, rtlResult = 0;
  19.  
  20.             System.Console.Title = "Aleksandra Aleksandra, Cezary Cezary";
  21.  
  22.             arrSize = Program.getArraySize();
  23.             System.Console.WriteLine(); // A co tam, nowa linia :)
  24.  
  25.             int[,] arr1 = new int[arrSize, arrSize];
  26.             int[,] arr2 = new int[arrSize, arrSize];
  27.  
  28.             Random rand = new Random();
  29.             // Wypełniamy tablice jakimiś śmieciami
  30.             for (int i = 0; i < arrSize; i++)
  31.                 for (int j = 0; j < arrSize; j++)
  32.                 {
  33.                     if (USE_SMALL_NUMBERS)
  34.                     {
  35.                         arr1[i, j] = rand.Next(SMALL_NUMBER_MAX);
  36.                         arr2[i, j] = rand.Next(SMALL_NUMBER_MAX);
  37.                     }
  38.                     else
  39.                     {
  40.                         arr1[i, j] = rand.Next();
  41.                         arr2[i, j] = rand.Next();
  42.                     }
  43.                 }
  44.  
  45.             // Narysujmy sobie to co robimy.
  46.             System.Console.ForegroundColor = ConsoleColor.Yellow;
  47.             System.Console.Write("Od lewej do prawej ");
  48.             System.Console.ForegroundColor = ConsoleColor.Blue;
  49.             System.Console.WriteLine("Od prawej do lewej");
  50.             System.Console.ForegroundColor = ConsoleColor.White;
  51.             for (int i = 0; i < arrSize; i++)
  52.             {
  53.                 for (int j = 0; j < arrSize; j++)
  54.                 {
  55.                     if (i == j)
  56.                     {
  57.                         System.Console.ForegroundColor = ConsoleColor.Yellow;
  58.                         ltrResult += arr1[i, j];
  59.                     }
  60.                     System.Console.Write(arr1[i, j] + " ");
  61.                     System.Console.ForegroundColor = ConsoleColor.White;
  62.  
  63.  
  64.                 }
  65.                 System.Console.Write(" | ");
  66.                 for (int jj = arrSize - 1; jj >= 0; jj--)
  67.                 {
  68.                     if (i == jj)
  69.                     {
  70.                         System.Console.ForegroundColor = ConsoleColor.Blue;
  71.                         rtlResult += arr2[i, jj];
  72.                     }
  73.                     System.Console.Write(arr2[i, jj] + " ");
  74.                     System.Console.ForegroundColor = ConsoleColor.White;
  75.  
  76.  
  77.                 }
  78.                 System.Console.WriteLine();
  79.             }
  80.  
  81.             System.Console.WriteLine(Environment.NewLine); // Nowa linia w nowej linii :)
  82.  
  83.             System.Console.ForegroundColor = ConsoleColor.Yellow;
  84.             System.Console.Write("Od lewej do prawej: ");
  85.             System.Console.ForegroundColor = ConsoleColor.White;
  86.             System.Console.WriteLine(ltrResult);
  87.             System.Console.ForegroundColor = ConsoleColor.Blue;
  88.             System.Console.Write("Od prawej do lewej: ");
  89.             System.Console.ForegroundColor = ConsoleColor.White;
  90.             System.Console.WriteLine(rtlResult);
  91.  
  92.             System.Console.WriteLine("FIN...");
  93.             System.Console.ReadLine();
  94.         }
  95.  
  96.  
  97.         // Pobiera od użytkownika rozmiar tablicy.
  98.         static int getArraySize()
  99.         {
  100.             int arrSize = 0;
  101.             while (arrSize == 0)
  102.             { // Dopóki arrsize jest zerem będziemy błagać o input
  103.                 System.Console.ForegroundColor = ConsoleColor.White;
  104.                 System.Console.Write("Podaj wielkość tablicy (x^2): ");
  105.                 try
  106.                 { // Gdyby jakiś dekiel chciał sobie wpisać śmieci ;D
  107.                     int tempSize = 0;
  108.                     tempSize = System.Convert.ToInt32(System.Console.ReadLine());
  109.  
  110.                     if (tempSize <= 0) // Pamiętaj, jednolinijkowe bloki nie muszą być w klamerce
  111.                         System.Console.WriteLine("Wielkość musi być większa od zera, ciołku");
  112.                     else
  113.                         arrSize = tempSize;
  114.                 }
  115.                 catch (Exception e)
  116.                 {
  117.                     System.Console.ForegroundColor = ConsoleColor.Red;
  118.                     System.Console.WriteLine("Teges, cyferki, nie literki (przykład: 1,2,3,4,5,6,7,8,9,0)");
  119.                 }
  120.             }
  121.  
  122.             return arrSize;
  123.  
  124.         }
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement