您的位置:首页 > 其它

USACO section 1.3

2010-03-16 20:02 176 查看
/*
ID: yan.yil1
PROG: calfflac
LANG: C++
*/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
bool Isch(char a)
{
if ((a>='a'&&a<='z')||(a>='A'&& a<='Z') )
return 1;
return 0;
}
char Tolit(char a)
{
if (!Isch(a)) return 1;
if (a>='A' && a <= 'Z') a = a+32;
return a;
}
char str[20005];
int len, maxans,maxb=0,maxe=0;

void Check(int b, int e)
{
if (str[b]!=str[e]&&Isch(str[b])&&Isch(str[e]))
return;
int i=b, j=e, k=0;
while (i>=0 && j < len)
{
while (i>=0 && !Isch(str[i])) i--;
while (j<len && !Isch(str[j])) j++;
if ( i>=0 && j < len && Tolit(str[i]) == Tolit(str[j]))
{
j++,i--;
k++;
} else break;
}
k = 2*k;
if (b==e) k--;
if (k > maxans)
{
maxans = k;
maxb = i+1, maxe = j-1;
}
}
int main()
{
FILE *fin,*fout;
fin=fopen("calfflac.in","r");
fout=fopen("calfflac.out","w");
len=0;
while(fscanf(fin,"%c",&str[len++])!=EOF);
int i, j, k;
maxans=1;
for (i=1; i<len-maxans; i++)
if (Isch(str[i]))
{
Check(i,i);
Check(i,i+1);
}
while (!Isch(str[maxb])) maxb++;
while (!Isch(str[maxe])) maxe--;
fprintf(fout,"%d/n",maxans);
for (i=maxb; i <= maxe; i++)
fprintf(fout,"%c",str[i]);
fprintf(fout,"/n");
fclose(fout);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: