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 second {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- Pattern pattern = Pattern.compile("[@][#]+([A-Z][A-Za-z0-9]{4,}[A-Z])[@][#]+");
- while (n-- > 0) {
- String input = scanner.nextLine();
- Matcher matcher = pattern.matcher(input);
- if (matcher.find()) {
- String product = matcher.group(1);
- StringBuilder code = new StringBuilder();
- for (int i = 0; i < product.length(); i++) {
- char symbol = product.charAt(i);
- if (Character.isDigit(symbol)) {
- code.append(symbol);
- }
- }
- if (code.length() > 0) {
- System.out.println(String.format("Product group: %s", code.toString()));
- } else if (code.length() == 0) {
- System.out.println("Product group: 00");
- }
- } else {
- System.out.println("Invalid barcode");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement