Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace Zad._4
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] sizes = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- string[,] matrix = new string[sizes[0], sizes[1]];
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- string[] rowValues = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- matrix[row, col] = rowValues[col];
- }
- }
- string input = Console.ReadLine();
- while (input!="END")
- {
- string[] commandInfo = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
- if (commandInfo.Length != 5)
- {
- Console.WriteLine("Invalid input!");
- input = Console.ReadLine();
- continue;
- }
- string swap = commandInfo[0];
- int rowOne = int.Parse(commandInfo[1]);
- int colOne = int.Parse(commandInfo[2]);
- int rowTwo = int.Parse(commandInfo[3]);
- int colTwo = int.Parse(commandInfo[4]);
- //int length = commandInfo.Skip(1).Count();
- if (swap != "swap" || commandInfo.Length!=5
- || rowOne >= matrix.GetLength(0)
- || rowTwo >= matrix.GetLength(0)
- || colOne >= matrix.GetLength(1)
- || colTwo >= matrix.GetLength(1)
- || rowOne < 0 || rowTwo < 0
- || colOne < 0 || colTwo < 0)
- {
- Console.WriteLine("Invalid input!");
- }
- else
- {
- string firstParameter = matrix[rowOne, colOne];
- string secondParameter = matrix[rowTwo, colTwo];
- matrix[rowOne, colOne] = secondParameter;
- matrix[rowTwo, colTwo] = firstParameter;
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- Console.Write(matrix[row, col] + " ");
- }
- Console.WriteLine();
- }
- }
- input = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement