// [5/4/2014 Sjm] /* 遍历,匹配即可。 注意:一个字符可以转换成多个字符。 */#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <string> #include <vector> using namespace std; string str1, str2; vector<char> myReplace[26]; void Solve() { int len1 = str1.size(), len2 = str2.size(); int tlen = 0; for (int i = 0; i < len2; i++) { if (str2[i] == str1[tlen]) tlen++; else { for (int j = myReplace[str2[i] - 'a'].size() - 1; j >= 0; j--) { if (str1[tlen] == myReplace[str2[i] - 'a'][j]) { tlen++; break; } } } if (tlen == len1) { printf("happy\n"); return; } } printf("unhappy\n"); } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); myReplace[2].push_back('#'); int T; scanf("%d", &T); for (int t = 1; t <= T; t++) { memset(myReplace, 0, sizeof(myReplace)); printf("Case #%d: ", t); cin >> str1 >> str2; int n; scanf("%d", &n); while (n--) { char c1, c2; getchar(); scanf("%c %c", &c1, &c2); //cin >> c1 >> c2; myReplace[c1 - 'a'].push_back(c2); } Solve(); } return 0; }
思维训练 之 hdu 4545
最新推荐文章于 2020-07-21 20:37:03 发布
