Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.reflect.Array;
- import java.util.*;
- import java.util.stream.Collectors;
- import java.util.ArrayList;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<Integer> pirateship = Arrays.stream(scanner.nextLine().split("\\>"))
- .map(element->Integer.parseInt(element)).collect(Collectors.toList());
- List<Integer> warship = Arrays.stream(scanner.nextLine().split("\\>"))
- .map(element->Integer.parseInt(element)).collect(Collectors.toList());
- int health= Integer.parseInt(scanner.nextLine());
- String command = scanner.nextLine();
- boolean xxxxxxxxxx = true;
- while (!command.equals("Retire")){
- String[]tokens = command.split(" ");
- String komandichka = tokens[0];
- if(komandichka.equals("Fire")){
- int index = Integer.parseInt(tokens[1]);
- int damage =Integer.parseInt(tokens[2]);
- if( index>=0 && index<warship.size()){
- int current = warship.get(index)-damage;
- if( current>0){
- warship.set(index,current);
- }else {
- System.out.println("You won! The enemy ship has sunken.");
- xxxxxxxxxx =false;
- break;
- }}}else if( komandichka.equals("Defend")){
- int startindex = Integer.parseInt(tokens[1]);
- int endtindex = Integer.parseInt(tokens[2]);
- int damageee = Integer.parseInt(tokens[3]);
- if( startindex>=0 && startindex<pirateship.size()&& endtindex>=0 && endtindex<pirateship.size()){
- if(startindex<=endtindex){
- for (int i=startindex ; i<= endtindex ;i++){
- int current = pirateship.get(i)-damageee;
- if( current>0){
- pirateship.set(i,current);
- }else {
- System.out.println("You lost! The pirate ship has sunken.");
- xxxxxxxxxx =false;
- break;
- }}}else {
- for (int i=endtindex; i<= startindex ;i++){
- int current = pirateship.get(i)-damageee;
- if( current>0){
- pirateship.set(i,current);
- }else {
- System.out.println("You lost! The pirate ship has sunken.");
- break;
- }}
- }}}else if(komandichka.equals("Repair")){
- int index = Integer.parseInt(tokens[1]);
- int lechenie = Integer.parseInt(tokens[2]);
- if( index>=0 && index<pirateship.size()){
- int tekushtichka = pirateship.get(index)+lechenie;
- if(tekushtichka<=health){
- pirateship.set(index,tekushtichka);
- }else {
- pirateship.set(index,health);
- }
- }
- }else {
- int count = 0;
- for(int i =0 ;i<pirateship.size();i++){
- if(pirateship.get(i)<0.2*health){
- count++;
- }
- }
- System.out.printf("%d sections need repair.",count);
- System.out.println();
- }
- command =scanner.nextLine();
- }
- if(xxxxxxxxxx){
- int xxx = 0;
- for(Integer num:pirateship){
- xxx = xxx+ num;
- }
- System.out.printf("Pirate ship status: %d",xxx);
- System.out.println();
- int yyyyy = 0 ;
- for( Integer huuu:warship){
- yyyyy = yyyyy+huuu;
- }
- System.out.printf("Warship status: %d",yyyyy);
- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement