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);
- List<String> items = Arrays.stream(scanner.nextLine().split("\\|")).collect(Collectors.toList());
- String line = scanner.nextLine();
- while (!"Done".equals(line)) {
- String[] tokens = line.split("\\s+");
- switch (tokens[1]) {
- case "Left":
- int index = Integer.parseInt(tokens[2]);
- if (index < items.size()&& index >= 1) {
- Collections.swap(items, index, index - 1);
- }
- break;
- case "Right":
- int index1 = Integer.parseInt(tokens[2]);
- if (index1 < items.size() - 1 && index1 >= 0) {
- Collections.swap(items, index1, index1 + 1);
- }
- break;
- case "Even":
- List<String> even = new ArrayList<>();
- for (int i = 0; i < items.size(); i += 2) {
- even.add(items.get(i));
- }
- System.out.println(String.join(" ", even));
- break;
- case "Odd":
- List<String> odd = new ArrayList<>();
- for (int i = 1; i < items.size(); i += 2) {
- odd.add(items.get(i));
- }
- System.out.println(String.join(" ", odd));
- break;
- }
- line = scanner.nextLine();
- }
- System.out.println("You crafted " + String.join("", items) + "!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement