Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _4._Matrix_shuffling
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] sizes = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToArray();
- string[][] matrix = new string[sizes[0]][];
- for (int i = 0; i < sizes[0]; i++)
- {
- matrix[i] = new string[sizes[1]];
- matrix[i] = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- }
- while (true)
- {
- string line = Console.ReadLine();
- if (line == "END")
- {
- break;
- }
- string[] tokens = line
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- if (tokens[0] != "swap" || tokens.Length != 5)
- {
- Console.WriteLine("Invalid input!");
- continue;
- }
- int r1 = int.Parse(tokens[1]);
- int c1 = int.Parse(tokens[2]);
- int r2 = int.Parse(tokens[3]);
- int c2 = int.Parse(tokens[4]);
- if (r1 >= matrix.Length
- || c1 >= sizes[1]
- || r2 >= matrix.Length
- || c2 >= sizes[1])
- {
- Console.WriteLine("Invalid input!");
- }
- else
- {
- string temporary = matrix[r2][c2];
- matrix[r2][c2] = matrix[r1][c1];
- matrix[r1][c1] = temporary;
- for (int i = 0; i < sizes[0]; i++)
- {
- Console.WriteLine(string.Join(' ', matrix[i]));
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement