//水题,并且我用的这种方法,太过死板了...反正不太好... #include <iostream> #include <cstring> #include <algorithm> const int N = 1e8; using namespace std; char a[N], b[N]; int main() { while (cin >> a >> b) { int len1 = strlen(a); int len2 = strlen(b); // sort(a, a+len1); // sort(b, b+len2); // cout << a << endl << b << endl; bool flag = true; for (int i = 0; i < len1; ) for (int j = 0; j < len2; j++) { if (b[j] == a[i]) { i++; if (i == len1) j = len2; continue; } if (j == len2 - 1) { flag = false; i = len1; break; } } if (flag) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
//代码果然总是别人的更简洁,唉 #include <iostream> #include <string> using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(false); string a, b; while (cin >> a >> b) { int cnt = 0; for (int i = 0; i < b.size(); i++) if (a[cnt] == b[i]) cnt++; if (cnt == a.size()) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }