Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PracticeMidExam;
- import java.lang.reflect.Array;
- import java.sql.SQLOutput;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Scanner;
- public class ArcheryTournament {
- public static void main(String[] arg) {
- Scanner sc = new Scanner(System.in);
- int[] numbers = Arrays.stream(sc.nextLine().split("\\|"))
- .mapToInt(e -> Integer.parseInt(e)).toArray();
- String input = sc.nextLine();
- int iskrenPoints = 0;
- int[] reverseNumbers = new int[numbers.length];
- while(!"Game Over".equals(input)){
- String[] commands = input.split("@");
- String command = commands[0];
- int starIndex = 0;
- int length = 0;
- if("Shoot Left".equals(command)) {
- starIndex = Integer.parseInt(commands[1]);
- length = Integer.parseInt(commands[2]);
- if(starIndex >=0 && starIndex < numbers.length){
- while(length !=0){
- if (starIndex > 0) {
- starIndex--;
- length--;
- }else if (starIndex == 0){
- starIndex = numbers.length-1;
- length--;
- }
- }
- if(numbers[starIndex] >= 5){
- numbers[starIndex] -= 5;
- iskrenPoints+=5;
- }else{
- iskrenPoints +=numbers[starIndex];
- numbers[starIndex] = 0;
- }
- }
- }
- else if ("Shoot Right".equals(command)){
- starIndex = Integer.parseInt(commands[1]);
- length = Integer.parseInt(commands[2]);
- if(starIndex >=0 && starIndex < numbers.length){
- while (length !=0){
- if(starIndex < numbers.length - 1){
- starIndex++;
- length--;
- }
- else if(starIndex == numbers.length-1){
- starIndex = 0;
- length--;
- }
- }
- if(numbers[starIndex] >=5){
- numbers[starIndex] -= 5;
- iskrenPoints += 5;
- }
- else{
- iskrenPoints += numbers[starIndex];
- numbers[starIndex] = 0;
- }
- }
- }
- else if("Reverse".equals(command)){
- for (int i = numbers.length-1; i >= 0 ; i--) {
- reverseNumbers[numbers.length-1-i] = numbers[i];
- }
- }
- input = sc.nextLine();
- }
- for (int number : reverseNumbers) {
- System.out.print(number + " " + "-");
- }
- System.out.println();
- System.out.printf("Iskren finished the archery tournament with %d points!", iskrenPoints);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement