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 ConsoleApplication7
- {
- class Program
- {
- static void Main(string[] args)
- {
- int rows = int.Parse(Console.ReadLine());
- int cols = int.Parse(Console.ReadLine());
- int[,] matrix = new int[rows, cols];
- string input = Console.ReadLine();
- List<int> measures = new List<int>();
- List<List<string>> swapper = new List<List<string>>();
- while (input != "END")
- {
- if (input.Length == 1)
- {
- measures.Add(int.Parse(input));
- }
- if (input.Length > 1)
- {
- string[] inputArray = input.Split(' ');
- List<string> toSwap = new List<string>();
- for (int i = 0; i < inputArray.Length; i++)
- {
- toSwap.Add(inputArray[i]);
- }
- swapper.Add(toSwap);
- }
- input = Console.ReadLine();
- }
- int counter = 0;
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- for (int j = 0; j < matrix.GetLength(1); j++)
- {
- matrix[i, j] = measures[counter];
- counter++;
- }
- }
- /*for (int k = 0; k < matrix.GetLength(0); k++)
- {
- for (int p = 0; p < matrix.GetLength(1); p++)
- {
- Console.Write(matrix[k, p] + " ");
- }
- Console.WriteLine();
- }*/
- int exceptionWriteRows = matrix.GetLength(0);
- int exceptionWriteCols = matrix.GetLength(1);
- foreach (var list in swapper)
- {
- if (list[0] == "swap")
- {
- string help = string.Empty;
- // for (int i = 0; i < list.Count; i++)
- //{
- // help.Join(list[i]);
- //}
- string[] helpTransformArray = help.Split(' ');
- int swappedRow = 0;
- int swappedCol = 0;
- int swapperRow = 0;
- int swapperCol = 0;
- swappedRow = int.Parse(list[1]);
- swappedCol = int.Parse(list[2]);
- swapperRow = int.Parse(list[3]);
- swapperCol = int.Parse(list[4]);
- if ((swappedRow < matrix.GetLength(0)) && (swappedCol < matrix.GetLength(1)) && (swapperRow < matrix.GetLength(0) && (swapperCol < matrix.GetLength(1))))
- {
- int hanger = matrix[swappedRow, swappedCol];
- matrix[swappedRow, swappedCol] = matrix[swapperRow, swapperCol];
- matrix[swapperRow, swapperCol] = hanger;
- Console.WriteLine("(after swapping {0} and {1}):", hanger, matrix[swappedRow, swappedCol]);
- printMatrix(matrix);
- }
- else
- {
- Console.WriteLine("Invalid input!");
- Console.WriteLine();
- }
- }
- else
- {
- Console.WriteLine("Invalid input!");
- Console.WriteLine();
- }
- }
- }
- static void printMatrix(int[,] matrix)
- {
- for (int k = 0; k < matrix.GetLength(0); k++)
- {
- for (int p = 0; p < matrix.GetLength(1); p++)
- {
- Console.Write(matrix[k, p] + " ");
- }
- Console.WriteLine();
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement