Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- string s, t;
- int n, m;
- cin>>n>>m;
- cin>>s>>t;
- int j = 0;
- int ans = 0;
- for (int i = 0; i<m; i++) {
- for (int k = 1; k<=n; k++) {
- ans++;
- if (s[k-1] == t[j]) {
- j++;
- if (j == m) {
- cout<<ans<<endl;
- return 0;
- }
- }
- }
- }
- cout<<-1<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment