Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace FirstProblem
- {
- public class FirstStartUp
- {
- public static void Main()
- {
- int numberOfRows = int.Parse(Console.ReadLine());
- var matrix = new string[numberOfRows][];
- for (int i = 0; i < numberOfRows; i++)
- {
- matrix[i] = Console.ReadLine().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- }
- string[] comandLine = Console.ReadLine().Split();
- int columHeadPosition = 0;
- for (int i = 0; i < matrix[0].Length; i++)
- {
- if (matrix[0][i] == comandLine[1])
- {
- columHeadPosition = i;
- break;
- }
- }
- if (comandLine[0] == "filter")
- {
- string filter = comandLine[2];
- Console.WriteLine(string.Join(" | ", matrix[0]));
- for (int row = 1; row < numberOfRows; row++)
- {
- if (matrix[row][columHeadPosition] == filter)
- {
- Console.WriteLine(string.Join(" | ", matrix[row]));
- }
- }
- }
- else if (comandLine[0] == "hide")
- {
- string filter = comandLine[1];
- for (int row = 0; row < numberOfRows; row++)
- {
- for (int col = 0; col < matrix[row].Length; col++)
- {
- if (col != columHeadPosition)
- {
- if (columHeadPosition == matrix[row].Length -1)
- {
- if (col != matrix[row].Length - 1 && col != matrix[row].Length - 2)
- {
- Console.Write(matrix[row][col] + " | ");
- }
- else
- {
- Console.Write(matrix[row][col]);
- }
- }
- else
- {
- if (col != matrix[row].Length - 1 )
- {
- Console.Write(matrix[row][col] + " | ");
- }
- else
- {
- Console.Write(matrix[row][col]);
- }
- }
- }
- }
- Console.WriteLine();
- }
- }
- else if (comandLine[0] == "sort")
- {
- string sortHeder = comandLine[1];
- for (int row = 1; row < numberOfRows -1; row++)
- {
- for (int rowNext = row + 1; rowNext < numberOfRows; rowNext++)
- {
- if (matrix[row][columHeadPosition].CompareTo(matrix[rowNext][columHeadPosition]) > 0)
- {
- string[] tempRow = matrix[rowNext];
- matrix[rowNext] = matrix[row];
- matrix[row] = tempRow;
- }
- }
- }
- for (int row = 0; row < numberOfRows; row++)
- {
- Console.WriteLine(string.Join(" | ", matrix[row]));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement