Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _02._Excel_Functions
- {
- class Program
- {
- static void Main(string[] args)
- {
- int _rows = int.Parse(Console.ReadLine());
- var table = new string[_rows][];
- for (int row = 0; row < table.Length; row++)
- {
- table[row] = Console.ReadLine().Split(", ", StringSplitOptions.RemoveEmptyEntries);
- }
- var command = Console.ReadLine().Split(" ",StringSplitOptions.RemoveEmptyEntries);
- var header = command[1];
- var index = -1;
- for (int col = 0; col < table[0].Length; col++)
- {
- if (table[0][col].Equals(header))
- {
- index = col;
- break;
- }
- }
- var result = table;
- switch (command[0])
- {
- case "hide":
- result = DeleteColumn(index, result);
- foreach (var row in result)
- {
- Console.WriteLine(string.Join(" | ", row));
- }
- break;
- case "sort":
- result = table.Skip(1).OrderBy(x => x[index]).ToArray();
- Console.WriteLine(string.Join(" | ", table[0]));
- foreach (var row in result)
- {
- Console.WriteLine(string.Join(" | ", row));
- }
- break;
- case "filter":
- var value = command[2];
- result = table.Skip(1).Where(x => x.Contains(value)).ToArray();
- Console.WriteLine(string.Join(" | ", table[0]));
- for (int row = 1; row < table.Length; row++)
- {
- if (table[row][index] == value)
- {
- Console.WriteLine(string.Join(" | ", table[row]));
- }
- }
- break;
- }
- }
- public static string[][] DeleteColumn(int columnToDelete, string[][] originalArray)
- {
- var result = new string[originalArray.Length][];
- for (int row = 0; row < originalArray.Length; row++)
- {
- int skippedCol = 0;
- result[row] = new string[originalArray[row].Length - 1];
- for (int col = 0; col < originalArray[row].Length - 1; col++)
- {
- if (skippedCol == columnToDelete)
- {
- skippedCol++;
- }
- result[row][col] = originalArray[row][skippedCol];
- skippedCol++;
- }
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement