Advertisement
ShSh99

PostOffice

Dec 12th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class PostOffice {
  8. public static void main(String[] args) {
  9. Scanner sc = new Scanner(System.in);
  10.  
  11. String[] line = sc.nextLine().split("\\|");
  12. String firstPart = line[0];
  13. String secondPart= line[1];
  14. String[] thirdPart =line[2].split(" ");
  15.  
  16. Pattern firstPattern = Pattern.compile("([$#%*&])[A-Z]+(\\1)");
  17. Matcher first = firstPattern.matcher(firstPart);
  18.  
  19. String code = "";
  20. if(first.find()){
  21. code = first.group(1);
  22. code = code.substring(1,code.length()-1);
  23. }
  24. for (int i = 0; i <code.length() ; i++) {
  25. String ascii = (int)code.charAt(i)+"";
  26. int index = secondPart.indexOf(ascii);
  27.  
  28. int length = 0;
  29. while (index != -1){
  30. char firstSymbol = secondPart.charAt(index+3);
  31. char secondSymbol = secondPart.charAt(index+4);
  32. if(Character.isDigit(firstSymbol) && Character.isDigit(secondSymbol)){
  33. length = Integer.parseInt(secondPart.substring(index+3,index+5))+1;
  34. break;
  35. }else {
  36. index = secondPart.indexOf(ascii,index+1);
  37. }
  38. }
  39. char capital = code.charAt(i);
  40. for (int j = 0; j < thirdPart.length; j++) {
  41. if(thirdPart[j].charAt(0) == capital && thirdPart[j].length() == length){
  42. System.out.println(thirdPart[j]);
  43. }
  44. }
  45.  
  46. }
  47.  
  48.  
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement