Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class BossRush {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- for (int i = 0; i < n; i++) {
- String input = scanner.nextLine();
- String regex = "\\|(?<boss>[A-Z]{4,})\\|:#(?<title>[A-Za-z]+ [A-Za-z]+)#";
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(input);
- if (matcher.find()){
- String boss = matcher.group(1);
- String title = matcher.group(2);
- int strength = boss.length();
- int armour = title.length();
- System.out.printf("%s, The %s%n",boss,title);
- System.out.printf(">> Strength: %d%n",strength);
- System.out.printf(">> Armour: %d%n",armour);
- } else {
- System.out.println("Access denied!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement