fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int p = -1;
  4. bool isSubsequence(const string& A, const string& B) {
  5. int n = A.size();
  6. int m = B.size();
  7. int i = 0, j = 0, count = 0;
  8.  
  9. while (i < m && j < n) {
  10. if (A[j] == B[i]) {
  11. if(count==0){
  12. p = j;
  13. }
  14.  
  15. i++;
  16. j++;
  17. count++;
  18. } else {
  19. j++;
  20. }
  21. }
  22.  
  23. return count == m;
  24. }
  25.  
  26. int main() {
  27.  
  28. int t;
  29. cin>>t;
  30. while(t--){
  31. string a,b;
  32. cin>>a;
  33. cin>>b;
  34. int answer = -1;
  35. for(int i=1;i<b.size();i++){
  36.  
  37. for(char c='a';c<='z';c++){
  38. string r = b ;
  39. r[i] = c;
  40. p = -1;
  41. if (isSubsequence(a, r)) {//p!=-1
  42. answer = p+1;
  43. }
  44. }
  45.  
  46. }
  47. cout<<answer;
  48. cout<<"\n";
  49.  
  50. }
  51. return 0;
  52. }
Success #stdin #stdout 0.01s 5284KB
stdin
2
abcbc
cba
lhs
rhs
stdout
3
-1