momo3141

Title Search

Nov 17th, 2022
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. let titleString = gets().split('')
  2. let N = +gets()
  3. let compareArray = []
  4. let indexArray = []
  5. let isIncluded = true
  6. let start = 0
  7. for(let i=1;i<=N;i++){
  8. let currentString = gets().split('')
  9. compareArray = titleString.slice()
  10. for (let j=0; j<=currentString.length-1;j++){
  11. indexArray.push(compareArray.slice(start).indexOf(currentString[j])+start)
  12. if(compareArray.slice(start).indexOf(currentString[j]) > -1){
  13. // start = compareArray.indexOf(currentString[j]) + 1
  14. compareArray[indexArray[j]]=' '
  15. start = compareArray.lastIndexOf(' ')
  16. } else {
  17. isIncluded = false
  18. break;
  19. }
  20. }
  21.  
  22. if(isIncluded){
  23. compareArray = compareArray.join().split(/\s|,/).filter(Boolean)
  24. titleString = compareArray.slice()
  25. print(titleString.join(''))
  26.  
  27. } else {
  28. print(`No such title found!`)
  29.  
  30. }
  31. indexArray = []
  32. isIncluded = true
  33. start = 0
  34.  
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment