二维数组实现字典树 比较方便
#include <iostream>
#include <string>
using namespace std;
bool tri[100000][26] = { false };
void Insert(string& str) {
int n = str.length();
for (int i = 0; i < n; i++) {
auto idx = str[i] - 'a';
tri[i][idx] = true;
}
}
bool research(string& str) {
int n = str.length();
for (int i = 0; i < n; i++) {
auto idx = str[i] - 'a';
if (!tri[i][idx])return false;
}
return true;
}
int main() {
string str1 = "", str2 = "";
while (cin >> str1 >> str2) {
Insert(str1);
if (research(str2))cout << "YES" << endl;
else cout << "NO" << endl;
}
}