Advertisement
Ankit_132

B

Jun 27th, 2024
1,124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int t;
  6.     cin>>t;
  7.     while(t--){
  8.         string s;
  9.         cin>>s;
  10.         string p;
  11.         cin>>p;
  12.         int n=s.length();
  13.         int m=p.length();
  14.         int ans=n+m;
  15.         for(int i=0;i<m;i++){
  16.             int ind=i;
  17.             for(int j=0;j<n;j++){
  18.                 if(ind<m && s[j] == p[ind]) ind++;
  19.             }
  20.             ans=min(ans,n+m-ind+i);
  21.         }
  22.        
  23.         cout<<ans<<endl;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement