Advertisement
Guest User

TitleSearch

a guest
Jun 2nd, 2023
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TitleSearch {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6. String word = scan.nextLine();
  7. int n = Integer.parseInt(scan.nextLine());
  8.  
  9. for (int i = 0; i < n; i++) {
  10. String input = scan.nextLine().toLowerCase();
  11. StringBuilder result = new StringBuilder(word);
  12. int index = 0;
  13.  
  14. for (int j = 0; j < result.length(); j++) {
  15. if (index < input.length() && input.charAt(index) == result.charAt(j)) {
  16. index++;
  17. result.deleteCharAt(j);
  18. j--;
  19. }
  20. }
  21.  
  22. if (index == input.length()) {
  23. System.out.println(result);
  24. word = result.toString();
  25. } else {
  26. System.out.println("No such title found!");
  27. }
  28. }
  29. }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement