| 记录编号 |
578444 |
评测结果 |
AAAA |
| 题目名称 |
3473.[POJ 3974]最长回文子串 |
最终得分 |
100 |
| 用户昵称 |
ムラサメ |
是否通过 |
通过 |
| 代码语言 |
C++ |
运行时间 |
0.013 s |
| 提交时间 |
2023-03-17 19:13:33 |
内存使用 |
1.73 MiB |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
string s;
int len,num=0,cnt,ans;
void work(int l,int r){
if(l<0||r>len||s[l]!=s[r]){
return;
}
else{
cnt+=2;
work(l-1,r+1);
}
}
int main(){
freopen("palindrome.in","r",stdin);
freopen("palindrome.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
while(cin>>s,s!="END"){
num++;
len=s.length();
ans=-1;
for(double i=0.5;i<=len-0.5;i+=0.5){
if(floor(i)!=i){
cnt=0;
work(floor(i),ceil(i));
ans=max(ans,cnt);
}
else{
cnt=1;
work(i-1,i+1);
ans=max(ans,cnt);
}
}
cout<<"Case "<<num<<": "<<ans<<endl;
}
return 0;
}