#include #include #include #include #include #include #include #include #include #include #include #pragma warning(disable:4996) using std::cin; using std::cout; using std::endl; using std::stringstream; using std::string; using std::vector; using std::list; using std::pair; using std::set; using std::multiset; using std::map; using std::multimap; using std::stack; using std::queue; using std::priority_queue; using std::bitset; bool isSlump(const string &str) { int state = 0;//当前状态 for (size_t i = 0; i < str.size(); i++) { switch (state) { case 0: { if (str[i] == 'D' || str[i] == 'E') { state = 1; } else { return false; } }break; case 1: { if (str[i] == 'F') { state = 2; } else { return false; } }break; case 2: { if (str[i] == 'D' || str[i] == 'E') { state = 1; } else if (str[i] == 'F') { ; } else if (str[i] == 'G') { state=3; } else { return false; } }break; case 3: { return false; }break; default:break; } } if (state == 3) { return true; } return false; } bool isSlimp(string str) { if (str.size() < 2) { return false; } if (str.size() == 2) { if (str == "AH") { return true; } else { return false; } } else { if (str[0] == 'A'&&str[1] == 'B'&&str[str.size() - 1] == 'C') { string tmp; tmp.assign(str.begin() + 2, str.begin()+str.size()-1); return isSlimp(tmp); } else if (str[0] == 'A'&&str[str.size() - 1] == 'C') { string tmp; tmp.assign(str.begin() + 1, str.begin() + str.size() - 1); return isSlump(tmp); } else { return false; } } } bool isSlurpy(const string &str) { for (int i = str.size() - 1; i >= 0; i--) { if (str[i] == 'H' || str[i] == 'C') { string slimp; slimp.assign(str.begin(), str.begin() + i + 1); string slump; slump.assign(str.begin() + i + 1, str.end()); if (isSlimp(slimp) && isSlump(slump)) { return true; } return false; } } return false; } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int T; while (cin >> T) { cout << "SLURPYS OUTPUT" << endl; string str; while (T--&&cin >> str) { if (isSlurpy(str)) { cout << "YES" << endl; } else { cout << "NO" << endl; } } } cout << "END OF OUTPUT" << endl; return 0; }