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 OlaOlaOlaAleksandraMalomowna
- {
- class Program
- {
- const bool IS_DEBUG = true;
- const bool USE_SMALL_NUMBERS = true; // Random lubi wywalać różne smoki z siebie, lepiej go ograniczyć jeśli chcemy weryfikować działanie programu
- const int SMALL_NUMBER_MAX = 9;
- static void Main(string[] args)
- {
- int arrSize = 0;
- int ltrResult = 0, rtlResult = 0;
- System.Console.Title = "Aleksandra Aleksandra, Cezary Cezary";
- arrSize = Program.getArraySize();
- System.Console.WriteLine(); // A co tam, nowa linia :)
- int[,] arr1 = new int[arrSize, arrSize];
- int[,] arr2 = new int[arrSize, arrSize];
- Random rand = new Random();
- // Wypełniamy tablice jakimiś śmieciami
- for (int i = 0; i < arrSize; i++)
- for (int j = 0; j < arrSize; j++)
- {
- if (USE_SMALL_NUMBERS)
- {
- arr1[i, j] = rand.Next(SMALL_NUMBER_MAX);
- arr2[i, j] = rand.Next(SMALL_NUMBER_MAX);
- }
- else
- {
- arr1[i, j] = rand.Next();
- arr2[i, j] = rand.Next();
- }
- }
- // Narysujmy sobie to co robimy.
- System.Console.ForegroundColor = ConsoleColor.Yellow;
- System.Console.Write("Od lewej do prawej ");
- System.Console.ForegroundColor = ConsoleColor.Blue;
- System.Console.WriteLine("Od prawej do lewej");
- System.Console.ForegroundColor = ConsoleColor.White;
- for (int i = 0; i < arrSize; i++)
- {
- for (int j = 0; j < arrSize; j++)
- {
- if (i == j)
- {
- System.Console.ForegroundColor = ConsoleColor.Yellow;
- ltrResult += arr1[i, j];
- }
- System.Console.Write(arr1[i, j] + " ");
- System.Console.ForegroundColor = ConsoleColor.White;
- }
- System.Console.Write(" | ");
- for (int jj = arrSize - 1; jj >= 0; jj--)
- {
- if (i == jj)
- {
- System.Console.ForegroundColor = ConsoleColor.Blue;
- rtlResult += arr2[i, jj];
- }
- System.Console.Write(arr2[i, jj] + " ");
- System.Console.ForegroundColor = ConsoleColor.White;
- }
- System.Console.WriteLine();
- }
- System.Console.WriteLine(Environment.NewLine); // Nowa linia w nowej linii :)
- System.Console.ForegroundColor = ConsoleColor.Yellow;
- System.Console.Write("Od lewej do prawej: ");
- System.Console.ForegroundColor = ConsoleColor.White;
- System.Console.WriteLine(ltrResult);
- System.Console.ForegroundColor = ConsoleColor.Blue;
- System.Console.Write("Od prawej do lewej: ");
- System.Console.ForegroundColor = ConsoleColor.White;
- System.Console.WriteLine(rtlResult);
- System.Console.WriteLine("FIN...");
- System.Console.ReadLine();
- }
- // Pobiera od użytkownika rozmiar tablicy.
- static int getArraySize()
- {
- int arrSize = 0;
- while (arrSize == 0)
- { // Dopóki arrsize jest zerem będziemy błagać o input
- System.Console.ForegroundColor = ConsoleColor.White;
- System.Console.Write("Podaj wielkość tablicy (x^2): ");
- try
- { // Gdyby jakiś dekiel chciał sobie wpisać śmieci ;D
- int tempSize = 0;
- tempSize = System.Convert.ToInt32(System.Console.ReadLine());
- if (tempSize <= 0) // Pamiętaj, jednolinijkowe bloki nie muszą być w klamerce
- System.Console.WriteLine("Wielkość musi być większa od zera, ciołku");
- else
- arrSize = tempSize;
- }
- catch (Exception e)
- {
- System.Console.ForegroundColor = ConsoleColor.Red;
- System.Console.WriteLine("Teges, cyferki, nie literki (przykład: 1,2,3,4,5,6,7,8,9,0)");
- }
- }
- return arrSize;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement