Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int sizeOfField = Integer.parseInt(input.nextLine());
- String ladybugIndexes = input.nextLine();
- String commands;
- int swap;
- int [] arrayOfLadybugs = Arrays
- .stream(ladybugIndexes.split(" "))
- .mapToInt(Integer::parseInt)
- .toArray();
- int [] field = new int[sizeOfField];
- for(int i=0; i<field.length; i++) {
- for(int j=0; j<arrayOfLadybugs.length; j++) {
- if(i == arrayOfLadybugs[j]) {
- field[i] = 1;
- break;
- } else {
- field[i] = 0;
- }
- }
- }
- while(true) {
- commands = input.nextLine();
- if(commands.equals("end")) break;
- else{
- String[] commandsArray= commands.split(" ");
- int ladybugFromCommand = Integer.parseInt(commandsArray[0]);
- int movement = Integer.parseInt(commandsArray[2]);
- for(int i=0; i<field.length; i++) {
- if(ladybugFromCommand == i) {
- if(commandsArray[1].equals("right")) {
- if(i+movement < field.length) {
- if(field[i+movement] == 0) {
- field[i + movement] = 1;
- field[i] = 0;
- }
- else {
- for(int l=i; l<field.length; l++)
- {
- if(field[l] == 0) {
- field[l] = 1;
- field[i] = 0;
- break;
- }
- else field[i] = 0;
- }
- }
- }
- else field[i]=0;
- }
- else if(commandsArray[1].equals("left")) {
- if(i-movement >= 0) {
- if(field[i-movement] == 0) {
- field[i - movement] = 1;
- field[i] = 0;
- }
- else {
- for(int l=field.length-1; l>=i; l--)
- {
- if(field[l] == 0) {
- field[l] = 1;
- field[i] = 0;
- break;
- }
- else field[i]=0;
- }
- }
- }
- else field[i]=0;
- }
- }
- }
- }
- }
- for(int i=0; i<field.length; i++)
- {
- System.out.print(field[i]+ " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement