Advertisement
Guest User

Untitled

a guest
Jun 21st, 2019
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._Excel_Functions
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int n = int.Parse(Console.ReadLine());
  12. string[][] table = new string[n][];
  13.  
  14. for (int i = 0; i < n; i++)
  15. {
  16. string[] rowValues = Console.ReadLine()
  17. .Split(", ");
  18.  
  19. table[i] = rowValues;
  20. }
  21. string[] commandArgs = Console.ReadLine()
  22. .Split();
  23.  
  24. string command = commandArgs[0];
  25. string header = commandArgs[1];
  26.  
  27.  
  28. int headerIndex = Array.IndexOf(table[0], header);
  29.  
  30. if (command== "hide")
  31. {
  32.  
  33. for (int row = 0; row < table.Length; row++)
  34. {
  35. List<string> lineToPrint = new List<string>(table[row]);
  36.  
  37. lineToPrint.RemoveAt(headerIndex);
  38. Console.WriteLine(string.Join(" | ", lineToPrint));
  39.  
  40. table[row] = lineToPrint.ToArray();
  41. }
  42. }
  43. else if (command == "sort")
  44. {
  45. string[] headerRow = table[0];
  46.  
  47. Console.WriteLine(string.Join(" | ", headerRow));
  48.  
  49. table = table.OrderBy(x => x[headerIndex]).ToArray();
  50.  
  51. foreach (var row in table)
  52. {
  53. if (row != headerRow)
  54. {
  55. Console.WriteLine(string.Join(" | ", row));
  56. }
  57. }
  58. }
  59. else if (command == "filter")
  60. {
  61. string parameter = commandArgs[2];
  62. string[] headerRow = table[0];
  63.  
  64. Console.WriteLine(string.Join(" | ", headerRow));
  65.  
  66. for (int i = 0; i < table.Length; i++)
  67. {
  68. if (table[i][headerIndex] == parameter)
  69. {
  70. Console.WriteLine(string.Join(" | ", table[i]));
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement