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; }
相关文章推荐
- USACO Section 1.3
- USACO Section1.3 Mixing Milk 解题报告
- USACO Section 1.3 Calf Flac
- USACO Section 1.3 Mixing Milk
- USACO Section 1.3 Prime Cryptarithm 解题报告
- USACO Section 1.3 Barn Repair
- USACO Section 1.3: Calf Flac
- USACO Section 1.3 Greedy Algorithm
- USACO Section 1.3 Wormholes 解题报告
- USACO section 1.3 Mixing Milk[贪心算法]
- USACO section 1.3 Prime Cryptarithm
- USACO Section1.3 Wormholes 解题报告
- USACO Section 1.3 Prime Cryptarithm
- USACO Section 1.3: Mixing Milk
- USACO Section 1.3 Problems rest
- USACO Section 1.3 wormhole (暴力+模拟)
- USACO Section 1.3 Combination Lock 解题报告
- USACO section 1.3 Combination Lock
- USACO Section 1.3 Calf Flac
- USACO Section 1.3 Mixing Milk