Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class TitleSearch {
- public static void main(String[] args) {
- Scanner myScan=new Scanner(System.in);
- String title=myScan.nextLine();
- int n=Integer.parseInt(myScan.nextLine());
- for (int i = 0; i < n; i++) {
- String input = myScan.nextLine();
- int index=0;
- Deque<Integer> indexes=new ArrayDeque<>();
- for (int j = 0; j <input.length() ; j++) {
- for (int k = index; k < title.length(); k++) {
- if (title.charAt(k)==input.charAt(j)){
- indexes.push(k);
- index=k+1;
- break;
- }
- }
- }
- if (indexes.size()==input.length()){
- for (Integer in : indexes) {
- title=new StringBuilder(title).deleteCharAt(in).toString();
- }
- System.out.println(title);
- }else{
- System.out.println("No such title found!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment