Advertisement
MartinGeorgiev

Untitled

Aug 7th, 2019
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.00 KB | None | 0 0
  1. import java.lang.reflect.Array;
  2. import java.util.*;
  3. import java.util.stream.Collectors;
  4. import java.util.ArrayList;
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.       Scanner scanner = new Scanner(System.in);
  9.         List<Integer> pirateship = Arrays.stream(scanner.nextLine().split("\\>"))
  10.                 .map(element->Integer.parseInt(element)).collect(Collectors.toList());
  11.         List<Integer> warship = Arrays.stream(scanner.nextLine().split("\\>"))
  12.                 .map(element->Integer.parseInt(element)).collect(Collectors.toList());
  13.         int health= Integer.parseInt(scanner.nextLine());
  14.         String command = scanner.nextLine();
  15.         boolean xxxxxxxxxx = true;
  16.         while (!command.equals("Retire")){
  17.             String[]tokens = command.split(" ");
  18.             String komandichka = tokens[0];
  19.             if(komandichka.equals("Fire")){
  20.                 int index = Integer.parseInt(tokens[1]);
  21.                 int damage =Integer.parseInt(tokens[2]);
  22.                 if( index>=0 && index<warship.size()){
  23.                     int current = warship.get(index)-damage;
  24.                     if( current>0){
  25.                         warship.set(index,current);
  26.                     }else {
  27.                         System.out.println("You won! The enemy ship has sunken.");
  28.                         xxxxxxxxxx =false;
  29.                         break;
  30.                     }}}else if( komandichka.equals("Defend")){
  31.                 int startindex = Integer.parseInt(tokens[1]);
  32.                 int endtindex = Integer.parseInt(tokens[2]);
  33.                 int damageee = Integer.parseInt(tokens[3]);
  34.                 if( startindex>=0 && startindex<pirateship.size()&& endtindex>=0 && endtindex<pirateship.size()){
  35.                     if(startindex<=endtindex){
  36.                     for (int i=startindex ; i<= endtindex ;i++){
  37.                         int current = pirateship.get(i)-damageee;
  38.                         if( current>0){
  39.                             pirateship.set(i,current);
  40.                         }else {
  41.                             System.out.println("You lost! The pirate ship has sunken.");
  42.                             xxxxxxxxxx =false;
  43.                             break;
  44.                         }}}else {
  45.                         for (int i=endtindex; i<= startindex ;i++){
  46.                             int current = pirateship.get(i)-damageee;
  47.                             if( current>0){
  48.                                 pirateship.set(i,current);
  49.                             }else {
  50.                                 System.out.println("You lost! The pirate ship has sunken.");
  51.                                 break;
  52.                             }}
  53.                     }}}else if(komandichka.equals("Repair")){
  54.                 int index = Integer.parseInt(tokens[1]);
  55.                 int lechenie = Integer.parseInt(tokens[2]);
  56.                 if( index>=0 && index<pirateship.size()){
  57.                     int tekushtichka = pirateship.get(index)+lechenie;
  58.                     if(tekushtichka<=health){
  59.                         pirateship.set(index,tekushtichka);
  60.                     }else {
  61.                         pirateship.set(index,health);
  62.                     }
  63.                 }
  64.             }else {
  65.                 int count = 0;
  66.                 for(int i =0 ;i<pirateship.size();i++){
  67.                     if(pirateship.get(i)<0.2*health){
  68.                        count++;
  69.                     }
  70.                 }
  71.                 System.out.printf("%d sections need repair.",count);
  72.                 System.out.println();
  73.             }
  74.             command =scanner.nextLine();
  75.         }
  76.  
  77.         if(xxxxxxxxxx){
  78.         int xxx = 0;
  79.         for(Integer num:pirateship){
  80.             xxx = xxx+ num;
  81.         }
  82.         System.out.printf("Pirate ship status: %d",xxx);
  83.         System.out.println();
  84.         int yyyyy = 0 ;
  85.         for( Integer huuu:warship){
  86.             yyyyy = yyyyy+huuu;
  87.         }
  88.         System.out.printf("Warship status: %d",yyyyy);
  89.     }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement