Advertisement
Guest User

Untitled

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