Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ExcelFunctions
- {
- class Program
- {
- static void Main(string[] args)
- {
- int rows = int.Parse(Console.ReadLine());
- string[] header = Console.ReadLine().Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- var matrix = new string[rows, header.Length];
- for (int i = 0; i < header.Length; i++)
- {
- matrix[0, i] = header[i];
- }
- for (int i = 1; i < rows; i++)
- {
- string[] input = Console.ReadLine().Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- for (int j = 0; j < header.Length; j++)
- {
- matrix[i, j] = input[j];
- }
- }
- string[] commandArr = Console.ReadLine().Split();
- string command = commandArr[0];
- switch (command)
- {
- case "hide":
- {
- string searchedHeader = commandArr[1];
- var newMatrix = new string[matrix.GetLength(0), matrix.GetLength(1) - 1];
- int newMatrixRow = 0;
- int newMatrixCol = 0;
- for (int i = 0; i < matrix.GetLength(1); i++)
- {
- if (matrix[0, i] == searchedHeader)
- {
- i++;
- }
- for (int j = 0; j < matrix.GetLength(0); j++)
- {
- newMatrix[newMatrixRow, newMatrixCol] = matrix[j, i];
- newMatrixRow++;
- }
- newMatrixRow = 0;
- newMatrixCol++;
- }
- matrix = newMatrix;
- break;
- }
- case "sort":
- {
- break;
- }
- case "filter":
- {
- string searchedHeader = commandArr[1];
- string keyword = commandArr[2];
- var newMatrix = new string[2 , matrix.GetLength(1)];
- for (int i = 0; i < matrix.GetLength(1); i++)
- {
- if (matrix[0, i] == searchedHeader)
- {
- for (int j = 0; j < matrix.GetLength(0); j++)
- {
- if (matrix[j, i] == keyword)
- {
- int newMatrixRow = 0;
- int newMatrixCol = 0;
- for (int a = 0; a < matrix.GetLength(1); a++)
- {
- newMatrix[newMatrixRow, newMatrixCol] = matrix[0, a];
- newMatrixCol++;
- }
- newMatrixRow++;
- newMatrixCol = 0;
- for (int a = 0; a < matrix.GetLength(1); a++)
- {
- newMatrix[newMatrixRow, newMatrixCol] = matrix[j, a];
- newMatrixCol++;
- }
- matrix = newMatrix;
- }
- }
- break;
- }
- }
- break;
- }
- }
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- for (int j = 0; j < matrix.GetLength(1); j++)
- {
- Console.Write(matrix[i, j]);
- if (j < matrix.GetLength(1) - 1)
- {
- Console.Write(" | ");
- }
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement