Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exams.january2018;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class P03_Snowflake {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String firstLine = reader.readLine();
- String secondLine = reader.readLine();
- String thirdLine = reader.readLine();
- String fourthLine = reader.readLine();
- String fifthLine = reader.readLine();
- String surfaceRegex = "^([^a-zA-Z0-9]+)$";
- String mantleRegex = "^([0-9_]+)$";
- String middleRegex = "^([^a-zA-Z0-9]+)([0-9_]+)([a-zA-Z]+)([0-9_]+)([^a-zA-Z0-9]+)$";
- Pattern firstSurfacePattern = Pattern.compile(surfaceRegex);
- Matcher firstSurfaceMatcher = firstSurfacePattern.matcher(firstLine);
- Pattern firstMantlePattern = Pattern.compile(mantleRegex);
- Matcher firstMantleMatcher = firstMantlePattern.matcher(secondLine);
- Pattern middlePattern = Pattern.compile(middleRegex);
- Matcher middleMatcher = middlePattern.matcher(thirdLine);
- Pattern secondMantlePattern = Pattern.compile(mantleRegex);
- Matcher secondMantleMatcher = secondMantlePattern.matcher(fourthLine);
- Pattern secondSurfacePattern = Pattern.compile(surfaceRegex);
- Matcher secondSurfaceMatcher = secondSurfacePattern.matcher(fifthLine);
- boolean firstRow = firstSurfaceMatcher.find();
- boolean secondRow = firstMantleMatcher.find();
- boolean thirdRow = middleMatcher.find();
- boolean fourthRow = secondMantleMatcher.find();
- boolean fifthRow = secondSurfaceMatcher.find();
- if (firstRow && secondRow && thirdRow && fourthRow && fifthRow) {
- System.out.println("Valid");
- System.out.println(middleMatcher.group(3).length());
- } else {
- System.out.println("Invalid");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment