/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* NAME : Nursoltan PROB : calfflac LANG : C++ DATE : 24/06/11 19:25 */ #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <sstream> #include <iostream> #include <map> #include <set> #include <stack> #include <utility> #include <queue> using namespace std; #define MAX 100 #define INF INT_MAX #define eps (1e-9) #define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++) #define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--) #define CLR(_x) memset((_x),0,sizeof(_x)) #define SQR(_x) ((_x)*(_x)) #define all(_x) _x.begin(),_x.end() #define sz(_x) sizeof(_x) #define vc vector<int> #define pb push_back #define mp make_pair #define iss istringstream #define oss ostringstream #define px first #define py second typedef long long ll; typedef pair <int,int> point; int ABS(int _x){ return _x>0?_x:-_x; } bool isLetter(char ch){ return ((ch>='A' && ch<='Z') || (ch>='a' && ch<='z')); } char lower(char ch){ return (isupper(ch))?(ch-'A'+'a'):ch; } char t[20005]; int m; int go(int i, int j){ int ret=0; while(i>=0 && j<m && t[i]==t[j]) ret++,i--,j++; return ret; } int main(){ freopen("calfflac.in","r",stdin); freopen("calfflac.out","w",stdout); int len,ret,b,e,n=0; char s[20005]; int id[20005]; CLR(s); CLR(id); CLR(t); FOR(i,0,20005) id[i]=-1; char ch; while((ch=getchar())!=EOF) s[n++]=ch; m=0; FOR(i,0,n) if(isLetter(s[i])){ id[i]=m; t[m++]=lower(s[i]); } //FOR(i,0,m) cout<<t[i]; //cout<<endl; len=1; b=0; e=0; FOR(i,0,m-1){ int k,_len; k=go(i,i)-1; _len=2*k+1; if(_len>len){ len=_len; b=i-k; e=i+k+1; } k=go(i,i+1); _len=2*k; if(_len>len){ len=_len; b=i-k+1; e=i+k+1; } //cout<<go(i,i)<<" "<<go(i,i+1)<<endl; } cout<<len<<endl; int i=0; while(id[i]==-1 || id[i]<b) i++; while(i<n && id[i]==-1 || (id[i]>=b && id[i]<e)){ cout<<s[i]; if(id[i]==e-1) break; i++; } cout<<endl; //system("pause"); return 0; }