veronikaaa86

Ne Mi SE Smei vol. 2

Feb 21st, 2018
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1. package exams.january2018;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. public class P03_Snowflake {
  10.     public static void main(String[] args) throws IOException {
  11.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  12.  
  13.         String firstLine = reader.readLine();
  14.         String secondLine = reader.readLine();
  15.         String thirdLine = reader.readLine();
  16.         String fourthLine = reader.readLine();
  17.         String fifthLine = reader.readLine();
  18.  
  19.         //String regex = "(\\W+)|([0-9\\_]+)|([a-zA-Z]+)";
  20.         String surfaceRegex = "\\W+";
  21.         String mantleRegex = "[0-9_]+";
  22.         String middleRegex = "([^a-zA-Z0-9]+)([0-9_]+)([a-zA-Z]+)([0-9_]+)([^a-zA-Z0-9]+)";
  23.         String coreRegex = "[a-zA-Z]+";
  24.  
  25.         Pattern firstSurfacePattern = Pattern.compile(surfaceRegex);
  26.         Matcher firstSurfaceMatcher = firstSurfacePattern.matcher(firstLine);
  27.  
  28.         Pattern firstMantlePattern = Pattern.compile(mantleRegex);
  29.         Matcher firstMantleMatcher = firstMantlePattern.matcher(secondLine);
  30.  
  31.         Pattern middlePattern = Pattern.compile(middleRegex);
  32.         Matcher middleMatcher = middlePattern.matcher(thirdLine);
  33.  
  34. //        Pattern corePattern = Pattern.compile(coreRegex);
  35. //        Matcher coreMatcher = corePattern.matcher(thirdLine);
  36.  
  37.         Pattern secondMantlePattern = Pattern.compile(mantleRegex);
  38.         Matcher secondMantleMatcher = secondMantlePattern.matcher(fourthLine);
  39.  
  40.         Pattern secondSurfacePattern = Pattern.compile(surfaceRegex);
  41.         Matcher secondSurfaceMatcher = secondSurfacePattern.matcher(fifthLine);
  42.  
  43.         boolean firstRow = firstSurfaceMatcher.find();
  44.         boolean secondRow = firstMantleMatcher.find();
  45.         boolean thirdRow = middleMatcher.find();
  46.         boolean fourthRow = secondMantleMatcher.find();
  47.         boolean fifthRow = secondSurfaceMatcher.find();
  48. //        boolean core = coreMatcher.find();
  49.  
  50.         if (firstRow && secondRow && thirdRow && fourthRow && fifthRow) {
  51.             System.out.println("Valid");
  52. //            String coreStr = coreMatcher.group();
  53.             System.out.println(middleMatcher.group(3).length());
  54.         } else {
  55.             System.out.println("Invalid");
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment