Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
2
Indexable
Never
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String patternRegex = "\\|(?<boss>[A-Z]{4,})\\|:#(?<title>[A-Za-z]+ [A-Za-z]+)#";
        Pattern bossTitlePattern = Pattern.compile(patternRegex);

        int inputCount = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < inputCount; i++) {
            String inputLine = scanner.nextLine();
            Matcher matcher = bossTitlePattern.matcher(inputLine);
            if (matcher.find()) {
                String foundBoss = matcher.group("boss");
                String foundTitle = matcher.group("title");
                int bossStrength = foundBoss.length();
                int titleArmor = foundTitle.length();

                System.out.println(String.format("%s, The %s", foundBoss, foundTitle));
                System.out.println(String.format(">> Strength: %d", bossStrength));
                System.out.println(String.format(">> Armor: %d", titleArmor));
            } else {
                System.out.println("Access denied!");
            }
        }
    }
}