Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Array;
- import java.util.*;
- public class test {
- public static void main(String[] args) {
- Scanner scan= new Scanner(System.in);
- int inputsCount = Integer.parseInt(scan.nextLine());
- while (inputsCount > 0) {
- StringBuilder input = new StringBuilder(scan.nextLine());
- StringBuilder group = new StringBuilder();
- boolean valid = true;
- //validation #1
- for (int i = 0; i < input.length(); i++) {
- if (i == 0 && input.charAt(i) != '@') {
- valid = false;
- } else if (i == 1 && input.charAt(i) != '#') {
- valid = false;
- } else if (i == input.length() - 1 && input.charAt(i) != '#') {
- valid = false;
- }
- }
- int br = 1;
- int index1 = 0;
- int index2 = 0;
- //remove the first series of "@#..."
- if (valid) {
- while (input.charAt(br) == '#') {
- index1++;
- br++;
- }
- }
- input.replace(0, index1 + 1, "").reverse();
- //remove the last series of "@#..."
- if (valid) {
- br = 0;
- while (input.charAt(br) == '#') {
- index2++;
- br++;
- }
- }
- //validation #2
- if (input.charAt(br) != '@') {
- valid = false;
- }
- input.replace(0, index2 + 1, "").reverse();
- //validation #3
- if (input.length() < 6) {
- valid = false;
- }
- //validation #4
- char firstLetter = input.charAt(0);
- if (!Character.isUpperCase(firstLetter)) {
- valid = false;
- }
- //validation #5
- for (int i = 0; i < input.length(); i++) {
- if (!Character.isLetterOrDigit(input.charAt(i))) {
- valid = false;
- }
- }
- //validation #6
- char lastLetter = input.charAt(input.length() - 1);
- if (!Character.isUpperCase(lastLetter)) {
- valid = false;
- }
- for (int i = 0; i < input.length(); i++) {
- if (Character.isDigit(input.charAt(i))) {
- group.append(input.charAt(i));
- }
- }
- if(group.isEmpty()){
- group.append("00");
- }
- if (valid) {
- System.out.println("Product group: " + group);
- }
- else{
- System.out.println("Invalid barcode");
- }
- inputsCount--;
- }
- }
- }
- /*
- 3
- @#FreshFisH@#
- @###Brea0D@###
- @##Che4s6E@##
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement