Advertisement
AngelKejov

Boss_Rush

Aug 21st, 2020
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class Boss_Rush {
  8.  
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.         Pattern pattern = Pattern.compile("(?<bossName>\\|[A-Z]+\\|):#(?<title>[A-Z][a-z]+ \\w+#)");
  12.  
  13.         int n = Integer.parseInt(scanner.nextLine());
  14.  
  15.         for (int i = 0; i < n; i++) {
  16.             String input = scanner.nextLine();
  17.             Matcher matcher = pattern.matcher(input);
  18.  
  19.             if (matcher.find()) {
  20.                 System.out.println();
  21.                 String bossName = matcher.group("bossName");
  22.                 String title = matcher.group("title");
  23.  
  24.                 String removeSymbol = title.substring(title.length() - 1, title.length());
  25.  
  26.                 System.out.printf("%s, The %s%n", bossName.replace("|", "")
  27.                         , title.replace(removeSymbol, ""));
  28.                 System.out.printf(">> Strength: %d%n>> Armour: %d", bossName.length() - 2, title.length() - 1);
  29.                 System.out.println();
  30.  
  31.             } else {
  32.                 System.out.print("Access denied!");
  33.             }
  34.         }
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement