Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.83 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace FirstProblem
  6. {
  7.     public class FirstStartUp
  8.     {
  9.         public static void Main()
  10.         {
  11.             int numberOfRows = int.Parse(Console.ReadLine());
  12.             var matrix = new string[numberOfRows][];
  13.             for (int i = 0; i < numberOfRows; i++)
  14.             {
  15.                 matrix[i] = Console.ReadLine().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  16.  
  17.             }
  18.             string[] comandLine = Console.ReadLine().Split();
  19.             int columHeadPosition = 0;
  20.             for (int i = 0; i < matrix[0].Length; i++)
  21.             {
  22.                 if (matrix[0][i] == comandLine[1])
  23.                 {
  24.                     columHeadPosition = i;
  25.                     break;
  26.                 }
  27.                
  28.  
  29.             }
  30.             if (comandLine[0] == "filter")
  31.             {
  32.                 string filter = comandLine[2];
  33.                 Console.WriteLine(string.Join(" | ", matrix[0]));
  34.                 for (int row = 1; row < numberOfRows; row++)
  35.                 {
  36.                     if (matrix[row][columHeadPosition] == filter)
  37.                     {
  38.                         Console.WriteLine(string.Join(" | ", matrix[row]));
  39.                     }
  40.                 }
  41.             }
  42.             else if (comandLine[0] == "hide")
  43.             {
  44.                 string filter = comandLine[1];
  45.  
  46.            
  47.                 for (int row = 0; row < numberOfRows; row++)
  48.                 {
  49.                     for (int col = 0; col < matrix[row].Length; col++)
  50.                     {
  51.                         if (col != columHeadPosition)
  52.                         {
  53.                             if (columHeadPosition == matrix[row].Length -1)
  54.                             {
  55.                                 if (col != matrix[row].Length - 1 && col != matrix[row].Length - 2)
  56.                                 {
  57.                                     Console.Write(matrix[row][col] + " | ");
  58.                                 }
  59.                                 else
  60.                                 {
  61.                                     Console.Write(matrix[row][col]);
  62.                                 }
  63.                             }
  64.                             else
  65.                             {
  66.                                 if (col != matrix[row].Length - 1 )
  67.                                 {
  68.                                     Console.Write(matrix[row][col] + " | ");
  69.                                 }
  70.                                 else
  71.                                 {
  72.                                     Console.Write(matrix[row][col]);
  73.                                 }
  74.                             }
  75.                            
  76.                            
  77.                         }
  78.                     }
  79.                     Console.WriteLine();
  80.                 }
  81.             }
  82.             else if (comandLine[0] == "sort")
  83.             {
  84.                 string sortHeder = comandLine[1];
  85.  
  86.                 for (int row = 1; row < numberOfRows -1; row++)
  87.                 {
  88.                     for (int rowNext = row + 1; rowNext < numberOfRows; rowNext++)
  89.                     {
  90.                         if (matrix[row][columHeadPosition].CompareTo(matrix[rowNext][columHeadPosition]) > 0)
  91.                         {
  92.                             string[] tempRow = matrix[rowNext];
  93.                             matrix[rowNext] = matrix[row];
  94.                             matrix[row] = tempRow;
  95.                         }
  96.                     }
  97.                    
  98.                 }
  99.                 for (int row = 0; row < numberOfRows; row++)
  100.                 {
  101.                     Console.WriteLine(string.Join(" | ", matrix[row]));
  102.                 }
  103.             }
  104.            
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement