直接上代码 #include<bits/stdc++.h> using namespace std; int main(){ string S,D; cin>>S>>D; int i = 0; int n = S.size(); int m = D.size(); for (int j = 0;j < m;j++){ if (D[j] == S[i]){ i++; if (i == n){ cout<<j + 1; return 0; } } } cout<<-1; return 0; }
直接上代码 #include<bits/stdc++.h> using namespace std; int main(){ string S,D; cin>>S>>D; int i = 0; int n = S.size(); int m = D.size(); for (int j = 0;j < m;j++){ if (D[j] == S[i]){ i++; if (i == n){ cout<<j + 1; return 0; } } } cout<<-1; return 0; }