题解 | #神奇的字符#
神奇的字符
https://www.nowcoder.com/practice/0e92225d095e4e178f0c585d3300dca5
#include <bits/stdc++.h> using namespace std; int main() { int n, m,i(0),j(0); string s, t; cin >> n >> m >> s >> t; while(i < n-m && j < m){ if(s[i] == t[j]){ i++; j++; }else { i++; } } if(j != m ) cout << -1 << endl; else cout << i << endl; return 0; }