1、题目描述
代码:
#include <iostream> #include <string> using namespace std; const int MAX_LETTER = 26; int main() { string source; string target; cin>>source; cin>>target; int cnt[MAX_LETTER] = {0}; for (int i = 0; target[i] != '\0'; i++) { cnt[target[i] - 'a'] = 1; } for (int i = 0; source[i] != '\0'; i++) { cnt[source[i] - 'a'] = 0; } for (int i = 0; i < MAX_LETTER;i++) { if (cnt[i] == 1) { cout<< "-1" <<endl; return 0; } } int t = 0; int i = 0; int j = 0; while (target[i]) { t++; j = 0; while (target[i] && source[j]) { if (target[i] == source[j]) { i++; j++; } else { j++; } } } cout<<t<<endl; return 0; }