Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package E_2019_12_10_Mid;
- import java.util.Arrays;
- import java.util.Scanner;
- public class Task_02 {
- public static void printArrOneLine(int[] arr) {
- for (int i = 0; i < arr.length - 1; i++) {
- System.out.print(String.format("%d - ", arr[i]));
- }
- if (arr.length > 0)
- System.out.println(arr[arr.length - 1]);
- }
- public static int moveCellsArr (int start,int length,int size,String direction){
- int endInd = 0;
- if(direction.equals("Right"))
- endInd = (start + length) % size;
- else if (direction.equals("Left")){
- endInd = start;
- while (length > 0){
- endInd--;length--;
- if (endInd == - 1)
- endInd = size - 1;
- }
- }
- return endInd;
- }
- public static void main(String[] args) {
- Scanner console = new Scanner(System.in);
- int[] arr = Arrays.stream(console.nextLine().split("\\|")).mapToInt(e -> Integer.parseInt(e)).toArray();
- String command;
- int result = 0;
- while (!(command = console.nextLine()).equals("Game over")) {
- var split = command.split(" |@");
- String action = split[0];
- if (action.equals("Shoot")) {
- String direction = split[1];
- int startInd = Integer.parseInt(split[2]);
- int length = Integer.parseInt(split[3]);
- if (startInd >= 0 && startInd < arr.length) {
- int newPosition = moveCellsArr(startInd,length,arr.length,direction);
- if (arr[newPosition] >= 5) {
- arr[newPosition] -= 5;
- result += 5;
- } else if (arr[newPosition] > 0 && arr[newPosition] < 5) {
- result += arr[newPosition];
- arr[newPosition] = 0;
- }
- }
- } else if (command.equals("Reverse")){
- int[] reversed = new int[arr.length];
- int ind = 0;
- for (int i = arr.length - 1; i >= 0; i--) {
- reversed[ind] = arr[i];
- ind++;
- }
- arr = reversed;
- }
- }
- printArrOneLine(arr);
- System.out.println(String.format("Iskren finished the archery tournament with %d points!", result));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement