Advertisement
fbinnzhivko

Untitled

Jun 10th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         int rows = int.Parse(Console.ReadLine());
  9.  
  10.         List<List<int>> matrix = new List<List<int>>();
  11.  
  12.         for (int row = 0; row < rows; row++)
  13.             matrix.Add(Console.ReadLine().Split(' ').Select(int.Parse).ToList());
  14.        
  15.         while (true)
  16.         {
  17.             string[] input = Console.ReadLine().Split().ToArray();
  18.             if (input[0] == "end") break;
  19.  
  20.  
  21.             if (input[0] == "remove")
  22.             {
  23.  
  24.                 int index = int.Parse(input[3]);
  25.  
  26.                 if (input[1] == "positive")
  27.                 {
  28.                     if (input[2] == "row")
  29.                     {
  30.                         matrix[index].RemoveAll(x => x >= 0);
  31.                     }
  32.                     if (input[2] == "col")
  33.                     {
  34.                         for (int i = 0; i < rows; i++)
  35.                         {
  36.                             if (index < matrix[i].Count)
  37.                                 if (matrix[i][index] >= 0) matrix[i].RemoveAt(index);
  38.                         }
  39.                     }
  40.                 }
  41.  
  42.                 if (input[1] == "negative")
  43.                 {
  44.                     if (input[2] == "row")
  45.                     {
  46.                         matrix[index].RemoveAll(x => x < 0);
  47.                     }
  48.                     if (input[2] == "col")
  49.                     {
  50.                         for (int i = 0; i < rows; i++)
  51.                         {
  52.                             if (index < matrix[i].Count)
  53.                                 if (matrix[i][index] < 0) matrix[i].RemoveAt(index);
  54.                         }
  55.                     }
  56.                 }
  57.                 if (input[1] == "odd")
  58.                 {
  59.                     if (input[2] == "row")
  60.                     {
  61.                         matrix[index].RemoveAll(x => x % 2 != 0);
  62.                     }
  63.                     if (input[2] == "col")
  64.                     {
  65.                         for (int i = 0; i < rows; i++)
  66.                         {
  67.                             if (index < matrix[i].Count)
  68.                                 if (matrix[i][index] % 2 != 0) matrix[i].RemoveAt(index);
  69.                         }
  70.                     }
  71.                 }
  72.                 if (input[1] == "even")
  73.                 {
  74.                     if (input[2] == "row")
  75.                     {
  76.                         matrix[index].RemoveAll(x => x % 2 == 0);
  77.                     }
  78.                     if (input[2] == "col")
  79.                     {
  80.                         for (int i = 0; i < rows; i++)
  81.                         {
  82.                             if (index < matrix[i].Count)
  83.                                 if (matrix[i][index] % 2 == 0) matrix[i].RemoveAt(index);
  84.                         }
  85.                     }
  86.                 }
  87.             }
  88.             if (input[0] == "swap")
  89.             {
  90.                 int firstRow = int.Parse(input[1]);
  91.                 int secondRow = int.Parse(input[2]);
  92.                 List<int> tempArr = matrix[firstRow];
  93.                 matrix[firstRow] = matrix[secondRow];
  94.                 matrix[secondRow] = tempArr;
  95.             }
  96.  
  97.             if (input[0] == "insert")
  98.             {
  99.                 int row = int.Parse(input[1]);
  100.                 int element = int.Parse(input[2]);
  101.                 matrix[row].Insert(0, element);
  102.             }
  103.         }
  104.         for (int row = 0; row < matrix.Count; row++)
  105.             Console.WriteLine(string.Join(" ", matrix[row]));
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement