Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int line = Integer.parseInt(scanner.nextLine());
- List<String> header = Arrays.stream(scanner.nextLine().split(", +"))
- .collect(Collectors.toCollection(ArrayList::new));
- List<List<String>> table = new ArrayList<>();
- for (int row = 0; row < line - 1; row++) {
- List<String> input = Arrays.stream(scanner.nextLine().split(", +"))
- .collect(Collectors.toCollection(ArrayList::new));
- table.add(input);
- }
- String[] command = scanner.nextLine().split("\\s+");
- int colIndex = header.indexOf(command[1]);
- List<List<String>> result = new ArrayList<>();
- switch (command[0]) {
- case "sort":
- result = table.stream()
- .sorted(Comparator.comparing(a -> a.get(colIndex))).collect(Collectors.toList());
- break;
- case "hide":
- table.forEach(e -> e.remove(colIndex));
- header.remove(colIndex);
- result = table;
- break;
- case "filter":
- String toFilter = command[2];
- result = table.stream().filter(e -> e.get(colIndex).equals(toFilter)).collect(Collectors.toList());
- break;
- }
- System.out.println(String.join(" | ", header));
- result.forEach(e -> System.out.println(String.join(" | ", e)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement