Advertisement
bullit3189

Excel Functions

May 29th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. public class Program
  7. {
  8. public static void Main()
  9. {
  10. int rows = int.Parse(Console.ReadLine());
  11.  
  12. string[][] jagged = new string[rows][];
  13.  
  14. for(int row=0; row<rows; row++)
  15. {
  16. string[] currRow = Console.ReadLine().Split(new char[]{',',' '},StringSplitOptions.RemoveEmptyEntries);
  17.  
  18. jagged[row] = currRow;
  19. }
  20.  
  21. string[] commands = Console.ReadLine().Split();
  22. string action = commands[0];
  23. string header = commands[1];
  24.  
  25. if(action == "hide")
  26. {
  27. int headerCol = -1;
  28. headerCol = Array.IndexOf(jagged[0],header);
  29.  
  30. for(int row=0; row<rows; row++)
  31. {
  32. List<string> result = new List<string>();
  33.  
  34. for(int col=0; col<jagged[row].Length; col++)
  35. {
  36. if(col!=headerCol)
  37. {
  38. result.Add(jagged[row][col]);
  39. }
  40. }
  41. Console.WriteLine(string.Join(" | ",result));
  42. }
  43. }
  44. else if (action == "sort")
  45. {
  46. int headerCol = -1;
  47. headerCol = Array.IndexOf(jagged[0],header);
  48.  
  49. Console.WriteLine(string.Join(" | ",jagged[0]));
  50.  
  51. foreach(var line in jagged.OrderBy(x=>x[headerCol]))
  52. {
  53. if(!line.Contains(header))
  54. {
  55. Console.WriteLine(string.Join(" | ",line));
  56. }
  57. }
  58. }
  59. else if (action == "filter")
  60. {
  61. string filterValue = commands[2];
  62.  
  63. int headerCol = -1;
  64. headerCol = Array.IndexOf(jagged[0],header);
  65.  
  66. Console.WriteLine(string.Join(" | ",jagged[0]));
  67.  
  68. for(int row=0; row<rows; row++)
  69. {
  70. if(jagged[row][headerCol].Contains(filterValue))
  71. {
  72. Console.WriteLine(string.Join(" | ",jagged[row]));
  73. }
  74. }
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement