Advertisement
i_graurov

BossRush

Apr 3rd, 2020
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 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. int n = Integer.parseInt(scanner.nextLine());
  9. for (int i = 0; i < n; i++) {
  10. String input = scanner.nextLine();
  11. String regex = "\\|(?<boss>[A-Z]{4,})\\|:#(?<title>[A-Za-z]+ [A-Za-z]+)#";
  12. Pattern pattern = Pattern.compile(regex);
  13. Matcher matcher = pattern.matcher(input);
  14. if (matcher.find()){
  15. String boss = matcher.group(1);
  16. String title = matcher.group(2);
  17. int strength = boss.length();
  18. int armour = title.length();
  19. System.out.printf("%s, The %s%n",boss,title);
  20. System.out.printf(">> Strength: %d%n",strength);
  21. System.out.printf(">> Armour: %d%n",armour);
  22. } else {
  23. System.out.println("Access denied!");
  24. }
  25.  
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement