Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data.Odbc;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class Program
- {
- static void Main()
- {
- int rowsCount = int.Parse(Console.ReadLine());
- List<List<long>> table = new List<List<long>>();
- for (int i = 0; i < rowsCount; i++)
- {
- List<long> currentRow = Console.ReadLine().Split().Select(long.Parse).ToList();
- table.Add(currentRow);
- }
- string input = Console.ReadLine();
- while (input != "end")
- {
- string[] tokens = input.Split(new char []{' '},StringSplitOptions.RemoveEmptyEntries);
- if (tokens[0] == "remove")
- {
- string type = tokens[1];
- string postion = tokens[2];
- int index = int.Parse(tokens[3]);
- if (postion == "row")
- {
- if (index >= 0 && index <= table.Count - 1)
- {
- switch (type)
- {
- case "odd":
- table[index] = table[index].Where(n => n % 2 == 0).ToList();
- break;
- case "even":
- table[index] = table[index].Where(n => n % 2 != 0).ToList();
- break;
- case "negative":
- table[index] = table[index].Where(n => n >= 0).ToList();
- break;
- case "positive":
- table[index] = table[index].Where(n => n < 0).ToList();
- break;
- }
- }
- }
- else if (postion == "col")
- {
- foreach (List<long> row in table)
- {
- if (index >= 0 && index <= row.Count - 1)
- {
- if (type == "odd" && row[index] % 2 != 0)
- {
- row.RemoveAt(index);
- }
- else if (type == "even" && row[index] % 2 == 0)
- {
- row.RemoveAt(index);
- }
- else if (type == "positive" && row[index] % 2 >= 0)
- {
- row.RemoveAt(index);
- }
- else if (type == "negative" && row[index] < 0)
- {
- row.RemoveAt(index);
- }
- }
- }
- }
- }
- else if (tokens[0] == "swap")
- {
- int firstRow = int.Parse(tokens[1]);
- int secondRow = int.Parse(tokens[2]);
- if (firstRow >= 0 && firstRow <= table.Count - 1 && secondRow >= 0 && secondRow <= table.Count - 1)
- {
- List<long> firstRowTemp = table[firstRow].ToList();
- table[firstRow] = table[secondRow].ToList();
- table[secondRow] = firstRowTemp.ToList();
- }
- }
- else if (tokens[0] == "insert")
- {
- int row = int.Parse(tokens[1]);
- long element = long.Parse(tokens[2]);
- if (row >= 0 && row <= table.Count - 1)
- {
- table[row].Insert(0, element);
- }
- }
- input = Console.ReadLine();
- }
- foreach (var row in table)
- {
- Console.WriteLine($"{string.Join(" ", row)}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement