Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- public class Program
- {
- public static void Main()
- {
- int rows = int.Parse(Console.ReadLine());
- string[][] jagged = new string[rows][];
- for(int row=0; row<rows; row++)
- {
- string[] currRow = Console.ReadLine().Split(new char[]{',',' '},StringSplitOptions.RemoveEmptyEntries);
- jagged[row] = currRow;
- }
- string[] commands = Console.ReadLine().Split();
- string action = commands[0];
- string header = commands[1];
- if(action == "hide")
- {
- int headerCol = -1;
- headerCol = Array.IndexOf(jagged[0],header);
- for(int row=0; row<rows; row++)
- {
- List<string> result = new List<string>();
- for(int col=0; col<jagged[row].Length; col++)
- {
- if(col!=headerCol)
- {
- result.Add(jagged[row][col]);
- }
- }
- Console.WriteLine(string.Join(" | ",result));
- }
- }
- else if (action == "sort")
- {
- int headerCol = -1;
- headerCol = Array.IndexOf(jagged[0],header);
- Console.WriteLine(string.Join(" | ",jagged[0]));
- foreach(var line in jagged.OrderBy(x=>x[headerCol]))
- {
- if(!line.Contains(header))
- {
- Console.WriteLine(string.Join(" | ",line));
- }
- }
- }
- else if (action == "filter")
- {
- string filterValue = commands[2];
- int headerCol = -1;
- headerCol = Array.IndexOf(jagged[0],header);
- Console.WriteLine(string.Join(" | ",jagged[0]));
- for(int row=0; row<rows; row++)
- {
- if(jagged[row][headerCol].Contains(filterValue))
- {
- Console.WriteLine(string.Join(" | ",jagged[row]));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement