http://poj.org/problem?id=3617
#include<cstdio> #include<cstring> #include<iostream> #include<string> #include<algorithm> using namespace std; const int MAX_N=2000; char S[MAX_N+1]; int N; int main() { cin>>N; for(int i=0;i<N;i++) cin>>S[i]; int l=0, r=N-1; int count=0; while(r>=l) { bool left=true; for(int i=0; l+i<=r; i++) { if(S[l+i] < S[r-i]) { left=true; break; } else if(S[l+i] > S[r-i]) { left=false; break; } } if(left) cout<<S[l++]; else cout<<S[r--]; if(++count%80==0) cout<<endl; } return 0; }