Advertisement
CR7CR7

ss

Oct 15th, 2022
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class TitleSearch {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         String title = scan.nextLine();
  9.         int n = Integer.parseInt(scan.nextLine());
  10.         for (int i = 0; i < n; i++) {
  11.             char[] currentWord = scan.nextLine().toCharArray();
  12.             char[] copyOfTitle =title.toCharArray();
  13.             boolean contains = true;
  14.             int index = 0;
  15.             for (char letter : currentWord) {
  16.                 for (int j = index; j < copyOfTitle.length; j++) {
  17.                     if (letter == copyOfTitle[j]) {
  18.                         index = j;
  19.                         copyOfTitle[j] = ' ';
  20.                         contains = true;
  21.                         break;
  22.                     } else {
  23.                         contains = false;
  24.                     }
  25.                 }
  26.             }
  27.  
  28.             title = contains ? String.valueOf(copyOfTitle).replaceAll("\\s","") : title;
  29.             System.out.println(contains ? title : "No such title found!");
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement