Lyubohd

02. Boss Rush

Mar 26th, 2020
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         String regex = "\\|(?<boss>[A-Z]{4,})\\|:#(?<title>[A-Za-z]+ [A-Za-z]+)#";
  9.         Pattern pattern = Pattern.compile(regex);
  10.  
  11.         int n = Integer.parseInt(scan.nextLine());
  12.         for (int i = 0; i < n; i++) {
  13.             String input = scan.nextLine();
  14.             Matcher matcher = pattern.matcher(input);
  15.             if (matcher.find()) {
  16.                 String boss = matcher.group("boss");
  17.                 String title = matcher.group("title");
  18.                 System.out.println(String.format("%s, The %s", boss, title));
  19.                 System.out.println(String.format(">> Strength: %d", boss.length()));
  20.                 System.out.println(String.format(">> Armour: %d", title.length()));
  21.             } else {
  22.                 System.out.println("Access denied!");
  23.             }
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment