企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOP] ### L2-4. 最长对称子串 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 对给定的字符串,本题要求你输出最长对称子串的长度。例如,给定"Is PAT&TAP symmetric?",最长对称子串为"s PAT&TAP s",于是你应该输出11。 输入格式: 输入在一行中给出长度不超过1000的非空字符串。 输出格式: 在一行中输出最长对称子串的长度。 输入样例: Is PAT&TAP symmetric? 输出样例: 11 ``` #include <stdio.h> int main(void) { char str[100]; gets(str); int b[100]; int i,j1,j2; int max = 1; b[0] = 1; if(str[0] == str[1]) b[1] = 2; else b[1] = 1; for(i=2;i<strlen(str);i++) { b[i] = 1; j1 = i-1; j2 = i-b[i-1]-1; if(str[j1] == str[i]) b[i] = 2; if(str[j2] == str[i]) b[i] = b[i-1]+2; if(max < b[i]) max = b[i]; } printf("%d",max); return 0; } ```