Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- String regex = "^(\\$|%)([A-Z][a-z]{3,})\\1:\\s(\\[(\\d+)\\]\\|)(\\[(\\d+)\\]\\|)(\\[(\\d+)\\]\\|)$";
- Pattern pattern = Pattern.compile(regex);
- int firstNumberInText = 0;
- int secondNumberInText = 0;
- int thirdNumberInText = 0;
- for (int i = 0; i < n; i++) {
- String input = scanner.nextLine();
- Matcher matcher = pattern.matcher(input);
- if (matcher.find()) {
- String tagName = matcher.group(2);
- firstNumberInText = Integer.parseInt(matcher.group(4));
- secondNumberInText = Integer.parseInt(matcher.group(6));
- thirdNumberInText = Integer.parseInt(matcher.group(8));
- char firstAscii = (char) (firstNumberInText);
- char secondAscii = (char) (secondNumberInText);
- char thirdAscii = (char) (thirdNumberInText);
- System.out.printf("%s: %c%c%c%n", tagName, firstAscii, secondAscii, thirdAscii);
- } else {
- System.out.println("Valid message not found!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement