Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Weaponsmith {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String [] parts = scanner.nextLine().split("\\|");
- List<String> allparts = new ArrayList<>();
- for (int i = 0; i <parts.length ; i++) {
- allparts.add(parts[i]);
- }
- String [] command = (scanner.nextLine()).split(" ");
- while(!command[0].equals("Done")){
- if(command[0].equals("Move")){
- if(command[1].equals("Left")) {
- if(Integer.parseInt(command[2])<allparts.size() && Integer.parseInt(command[2])>0){
- Collections.swap(allparts,Integer.parseInt(command[2]),Integer.parseInt(command[2])-1);
- }
- }
- if(command[1].equals("Right")) {
- if(Integer.parseInt(command[2])<allparts.size()-1 && Integer.parseInt(command[2])>=0){
- Collections.swap(allparts,Integer.parseInt(command[2]),Integer.parseInt(command[2])+1);
- }
- }
- }
- if(command[0].equals("Check")) {
- if(command[1].equals("Even")){
- for (int i = 0; i < allparts.size(); i++) {
- if(i%2==0){
- System.out.print(allparts.get(i)+ " ");
- }
- }
- }
- if(command[1].equals("Odd")){
- for (int i = 0; i < allparts.size() ; i++) {
- if(i%2!=0){
- System.out.print(allparts.get(i)+ " ");
- }
- }
- }
- }
- command = (scanner.nextLine()).split(" ");
- }
- System.out.println();
- System.out.print("You crafted ");
- for (String allpart : allparts) {
- System.out.print(allpart);
- }
- System.out.print("!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement