Advertisement
Didart

Boss Rush

Dec 5th, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 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 BossRush {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String regex = "\\|(?<boss>[A-Z]{4,})\\|:#(?<title>[A-Za-z]+ [A-Za-z]+)#";
  10.        
  11.         Pattern pattern = Pattern.compile(regex);
  12.  
  13.         int n = Integer.parseInt(scanner.nextLine());
  14.         for (int i = 0; i < n; i++) {
  15.             String input = scanner.nextLine();
  16.             Matcher matcher = pattern.matcher(input);
  17.             if (matcher.find()) {
  18.                 String boss = matcher.group("boss");
  19.                 String title = matcher.group("title");
  20.                 System.out.println(String.format("%s, The %s", boss, title));               // System.out.printf("%s, The %s", boss, title);
  21.                 System.out.println(String.format(">> Strength: %d", boss.length()));        // System.out.printf(">> Strength: %d", boss.length());
  22.                 System.out.println(String.format(">> Armour: %d", title.length()));         // System.out.printf(">> Armour: %d", title.length());
  23.             } else {
  24.                 System.out.println("Access denied!");
  25.             }
  26.         }
  27.     }
  28. }
  29.    
  30.  
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement