/**//*
ID: lorelei3
TASK: calfflac
LANG: C++
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
const int N = 21000;
char fulltext[N];
char text[N];
int pallen,b;
int findpal(){
char *p, *fwd, *bkwd, *etext = text+strlen(text);
int tmp;
for(p=text; *p; ++p){
for(fwd=p,bkwd=p; fwd<etext && bkwd>=text && *fwd==*bkwd; fwd++, bkwd--);
bkwd++;
tmp=fwd-bkwd;
if(tmp>pallen){
pallen=tmp;
b=bkwd-text;
}
for(fwd=p,bkwd=p+1; fwd<etext && bkwd>=text && *fwd==*bkwd; fwd++, bkwd--);
bkwd++;
tmp=fwd-bkwd;
if(tmp>pallen){
pallen=tmp;
b=bkwd-text;
}
}
return 0;
}
int main(){
int i;
char *p, *q, ch;
FILE *fin, *fout;
fin = fopen("calfflac.in", "r");
fout = fopen("calfflac.out", "w");
p=fulltext;
q=text;
while((ch = getc(fin)) != EOF) {
if(isalpha(ch))
*q++ = tolower(ch);
*p++ = ch;
}
*p = '\0';
*q = '\0';
findpal();
fprintf(fout, "%d\n", pallen);
for(i=0, p=fulltext; *p; ++p)
if(isalpha(*p))
if(i++==b)
break;
for(i=0; i<pallen && *p; ++p){
fputc(*p, fout);
if(isalpha(*p))
i++;
}
fprintf(fout, "\n");
return 0;
}
posted on 2010-11-09 01:01
小阮 阅读(163)
评论(0) 编辑 收藏 引用 所属分类:
USACO