int testManacher() { int i, ans; while (scanf("%s", str1) != EOF) { nn = strlen(str1); n = 2 * nn + 2; str[0] = '$'; for (i = 0; i <= nn; ++i) { str[2 * i + 1] = '#'; str[2 * i + 2] = str1[i]; } Manacher(rad, str, n); ans = 1; for (i = 0; i < n; ++i) ans = rad[i] > ans ? rad[i] : ans; printf("%d\n", ans - 1); fflush(stdout); } return 0; }
int main() { while (~scanf("%s", s)) { int len = strlen(s), Mlen = (len << 1) + 2, mxlen = 0, mxpos = 0; Manacher(s, len); for (int i = 0; i < Mlen; i++) { if (mxlen < Mdp[i]) { mxlen = Mdp[i]; mxpos = i; } } printf("%d\n", mxlen - 1); //s.substr((mxpos - mxlen) >> 1, mxlen - 1); } }
int main() { int max,i; freopen("poj3974.txt","r",stdin); freopen("poj3974ans.txt","w",stdout); while (scanf("%s",s)!=EOF) { Manacher(s,len); max=0; for (i=0; i<slen; i++) if (max<len[i]-1) max=len[i]-1; printf("%d\n",max); } }
int main() { int t,i; scanf("%d",&t); while(t--) { scanf("%s",in_s); int len=strlen(in_s); s[0]='$'; for(i=0; i<=len; i++) { s[2*i+2]=in_s[i]; s[2*i+1]='#'; } int res=Manacher(s); if(res==10)printf("alindrome"); else if(res==20)printf("palindrome"); else printf("simple"); printf("\n"); } return 0; }
int main(int argc, char* argv[]) { std::ifstream file("gettysburg.txt"); std::string ori_str; std::string longest_parlin_str; std::string color_str; int find_pos = 0; file >> ori_str; longest_parlin_str = Manacher(ori_str); find_pos = ori_str.find(longest_parlin_str); color_str = ori_str.substr(0, find_pos) + "\033[33m" + longest_parlin_str + "\033[0m" + ori_str.substr(find_pos + longest_parlin_str.size(), ori_str.size() - find_pos - longest_parlin_str.size()); std::cout << color_str << std::endl; return 0; }
int main(){ while (scanf("%s", str) != EOF){ Manacher(str); } return 0; }
int innerJudge(const char* IStr, const char* BStr) { int nLenB = strlen(BStr); int nSameIndex = judgeSameIndex(BStr, nLenB); printf("same index = %d\n", nSameIndex); int nLenI = strlen(IStr); //judge the left index. int* extend = malloc(nSameIndex * sizeof(int) + 1); extendkmp(BStr, nSameIndex, IStr, nLenI, extend); extend[nSameIndex] = 0; //cat double str1 char* DBIStr = malloc(2 * nLenI + 1); memcpy(DBIStr, IStr, nLenI); memcpy(DBIStr + nLenI, IStr, nLenI); DBIStr[2 * nLenI] = '\0'; puts(DBIStr); //diff string int nLenRe = nLenB - 2 * nSameIndex; printf("Diff Length:%d\n", nLenRe); char* BReS = malloc(nLenRe + 1); memcpy(BReS, BStr + nSameIndex, nLenRe); BReS[nLenRe] = '\0'; revert(BReS, nLenRe); puts(BReS); //find the diff string length int* extend2 = malloc(2 * nLenI * sizeof(int)); extendkmp(DBIStr, 2 * nLenI, BReS , nLenRe, extend2); //get the fit condition index puts("fit condition index:"); int i; int min = nLenI > nLenRe ? nLenRe : nLenI; int matchIndex = -1; if (nLenRe >= nLenI) { if (!isPalindrome(BStr + nSameIndex, nLenRe - nLenI)) return -1; for (i = 0; i <= nSameIndex; ++i) { if (extend[i] + i >= nSameIndex) if (nSameIndex - i <= 2 * nLenI && extend2[nSameIndex - i] >= min) { printf("%d ", i); matchIndex = i; break; } } } else { int nn = 2 * nLenI; int n = 2 * nn + 2; char* str = malloc(n + 1); int* rad = malloc(n * sizeof(int)); str[0] = '$'; for (i = 0; i <= nn; ++i) { str[2 * i + 1] = '#'; str[2 * i + 2] = DBIStr[i]; } Manacher(rad, str, n); printArray("rad", rad, n); int nLenSum = nLenI + nLenRe; int nLenSub = nLenI - nLenRe; printf("nLenI = %d, nLenRe = %d\n", nLenI, nLenRe); for (i = 0; i <= nSameIndex; ++i) { if (extend[i] + i >= nSameIndex) if (nSameIndex - i <= 2 * nLenI && extend2[nSameIndex - i] >= min) { if (rad[2 * (nSameIndex - i) + nLenSum + 1] > nLenSub) { matchIndex = i; } } } } //judge the right index. return matchIndex; }