// [9/12/2014 Sjm]/*按题目要求进行模拟。。。当初比赛时,WA了4次才AC掉,仅仅因为一句话: The symbol A, B and C are different continuous non-empty substrings of the poem.*/
1 #include2 #include 3 #include 4 #include 5 using namespace std; 6 7 string Ini(string str) { 8 string t_str = ""; 9 for (int i = 0; i < str.size(); ++i) {10 if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') || (str[i] >= '1' && str[i] <= '9')) {11 t_str += str[i];12 }13 }14 return t_str;15 }16 17 bool JudgeOne(string str) {18 if (str.size() < 5) { return false; }19 int len = str.size();20 for (int i = 1; i <= len/3; ++i) {21 string t_str_begin = str.substr(0, i), t_str_end = str.substr(len - i, i);22 if (t_str_begin != t_str_end) { continue; }23 else {24 string t_str = str.substr(i, len - 2 * i);25 int t_len = t_str.size();26 if ((t_len - i)/2 == 0) { continue; }27 if (0 != (t_len - i) % 2) { continue; }28 string tt_str_be = t_str.substr(0, (t_len - i) / 2), tt_str_en = t_str.substr((t_len - i) / 2 + i, (t_len - i) / 2);29 if (tt_str_be != tt_str_en) { continue; }30 if (tt_str_be == t_str_begin) { continue; }31 string strToJudge = t_str.substr((t_len - i) / 2, i);32 if (strToJudge == t_str_begin) {33 return true;34 }35 }36 }37 return false;38 }39 40 bool JudgeTwo(string str) {41 if (str.size() < 7) { return false; }42 int len = str.size();43 for (int i = 2; i <= len/3; ++i) {44 string str_begin = str.substr(0, i), str_end = str.substr(len - i, i);45 if (str_begin != str_end) { continue; }46 if ((2 == i) && (str_begin[0] == str_begin[1])) { continue; }47 string t_str = str.substr(i, i);48 if (t_str == str_begin) {49 if (0 == len - i * 3) { continue; }50 string tt_str = str.substr(i * 2, len - i * 3);51 int mylen = t_str.size();52 for (int k = 1; k < mylen; ++k) {53 string A = t_str.substr(0, k);54 string B = t_str.substr(k, mylen - k);55 if (A != B && A != tt_str && B != tt_str) {56 return true;57 }58 }59 }60 }61 return false;62 }63 64 int main() {65 //freopen("input.txt", "r", stdin);66 int T;67 scanf("%d", &T);68 getchar();69 while (T--) {70 string str;71 getline(cin, str);72 str = Ini(str);73 if (JudgeOne(str) || JudgeTwo(str)) {74 printf("Yes\n");75 }76 else printf("No\n");77 }78 return 0;79 }