Calf Flac
来源:互联网 发布:淘宝退款怎么申请介入 编辑:程序博客网 时间:2024/06/13 03:51
Calf Flac
It is said that if you give an infinite number of cows an infinite number of heavy-duty laptops (with very large keys), that they will ultimately produce all the world's great palindromes. Your job will be to detect these bovine beauties.Ignore punctuation, whitespace, numbers, and case when testing for palindromes, but keep these extra characters around so that you can print them out as the answer; just consider the letters `A-Z' and `a-z'.
Find the largest palindrome in a string no more than 20,000 characters long. The largest palindrome is guaranteed to be at most 2,000 characters long before whitespace and punctuation are removed.
PROGRAM NAME: calfflac
INPUT FORMAT
A file with no more than 20,000 characters. The file has one or more lines which, when taken together, represent one long string. No line is longer than 80 characters (not counting the newline at the end).
SAMPLE INPUT (file calfflac.in)
Confucius say: Madam, I'm Adam.
OUTPUT FORMAT
The first line of the output should be the length of the longest palindrome found. The next line or lines should be the actual text of the palindrome (without any surrounding white space or punctuation but with all other characters) printed on a line (or more than one line if newlines are included in the palindromic text). If there are multiple palindromes of longest length, output the one that appears first.
SAMPLE OUTPUT (file calfflac.out)
11
Madam, I'm Adam
陷阱忒多了。。
/*ID: des_jas1PROG: calfflacLANG: C++*/#include <iostream>#include <fstream>#include <string>#include <ctype.h>#include <algorithm>//#define fin cin//#define fout coutusing namespace std;const int MAXN=20000+10; //要大string origin,after;int p[MAXN];int main() { ofstream fout ("calfflac.out"); ifstream fin ("calfflac.in");string tp;int i,j,m=0,max=0;string::size_type n; while(!fin.eof()){ getline(fin,tp); origin+=tp+"\n"; //不知道为什么它自动踢掉了\n,好吧自己动手。}n=origin.size();after=origin;//没有这个会死for(i=0;i<n;i++)if(isalpha(origin[i])){p[m]=i;after[m++]=toupper(origin[i]);} after.resize(m+1); //没有这个好像不会死。。int len,x,y; for(i=0;i<m;i++){for(j=0;i-j>=0 && i+j<m;j++){if(after[i-j]!=after[i+j]) break;len=j*2+1;if(len>max){max=len;x=p[i-j];y=p[i+j];}}for(j=0;i-j>=0 && i+j+1<m;j++){if(after[i-j]!=after[i+j+1]) break;len=(j+1)*2;if(len>max){max=len;x=p[i-j];y=p[i+j+1];}}}fout<<max<<endl;for(;x<=y;x++)fout<<origin[x];fout<<endl;fout.close();fin.close(); return 0;}
- Calf Flac
- Calf Flac
- Calf Flac
- Calf Flac
- Calf Flac
- Calf Flac
- Calf Flac
- Calf Flac(USACO)
- Chapter 1 Calf Flac
- USACO 1.3-Calf Flac
- Section 1.3 Calf Flac
- [USACO] Calf Flac
- usaco Calf Flac
- USACO 1.3 Calf Flac
- USACO 1.3 Calf Flac
- usaco Calf Flac
- USACO:Calf Flac
- USACO Calf Flac
- Zara不可复制的核心竞争力是怎么打造的?
- Linux Mysql 学习
- Spring事务配置的五种方式
- c# 将日志文件显示在WebBrowser控件中
- Cocos2d-x纹理优化的一些方案
- Calf Flac
- 如何在项目中引入.h、.lib和dll、以及.cpp
- android平台工程移植问题
- S2SH中java.lang.NoSuchMethodError错误分析
- 关于android ndk出现ReferenceTable overflow (max=1024)的解决方法
- 少编码多思考:代码越多 问题越多
- Arcgis Server javascript— EXT布局设计
- J2EE J2SE J2ME JDK SDK JRE JVM
- mysql编码格式问题