Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class PostOffice {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[] line = sc.nextLine().split("\\|");
- String firstPart = line[0];
- String secondPart= line[1];
- String[] thirdPart =line[2].split(" ");
- Pattern firstPattern = Pattern.compile("([$#%*&])[A-Z]+(\\1)");
- Matcher first = firstPattern.matcher(firstPart);
- String code = "";
- if(first.find()){
- code = first.group(1);
- code = code.substring(1,code.length()-1);
- }
- for (int i = 0; i <code.length() ; i++) {
- String ascii = (int)code.charAt(i)+"";
- int index = secondPart.indexOf(ascii);
- int length = 0;
- while (index != -1){
- char firstSymbol = secondPart.charAt(index+3);
- char secondSymbol = secondPart.charAt(index+4);
- if(Character.isDigit(firstSymbol) && Character.isDigit(secondSymbol)){
- length = Integer.parseInt(secondPart.substring(index+3,index+5))+1;
- break;
- }else {
- index = secondPart.indexOf(ascii,index+1);
- }
- }
- char capital = code.charAt(i);
- for (int j = 0; j < thirdPart.length; j++) {
- if(thirdPart[j].charAt(0) == capital && thirdPart[j].length() == length){
- System.out.println(thirdPart[j]);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement