Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Advanced
- {
- class Program
- {
- static void Main(string[] args)
- {
- var dimentions = Console.ReadLine()
- .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- int rows = dimentions[0];
- int cols = dimentions[1];
- var matrix = new string[rows, cols];
- for (int row = 0; row < rows; row++)
- {
- var currentRow = Console.ReadLine()
- .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- for (int col = 0; col < cols; col++)
- {
- matrix[row, col] = currentRow[col];
- }
- }
- while (true)
- {
- var input = Console.ReadLine();
- if (input == "END")
- {
- break;
- }
- var line = input.Split().ToArray();
- var command = line[0];
- if (command != "swap" || line.Length != 5)
- {
- Console.WriteLine("Invalid input!");
- }
- else
- {
- var row1 = int.Parse(line[1]);
- var col1 = int.Parse(line[2]);
- var row2 = int.Parse(line[3]);
- var col2 = int.Parse(line[4]);
- if (row1 < 0 || row1 >= rows
- || col1 < 0 || col1 >= cols
- || row2 < 0 || row2 >= rows
- || col2 < 0 || col2 >= cols)
- {
- Console.WriteLine("Invalid input!");
- }
- else
- {
- var firstIndex = matrix[row1, col1];
- var secondIndex = matrix[row2, col2];
- matrix[row1, col1] = secondIndex;
- matrix[row2, col2] = firstIndex;
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < cols; col++)
- {
- Console.Write(matrix[row, col] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement