poj3617 Best Cow Line

来源:互联网 发布:幼儿园网络研修的简报 编辑:程序博客网 时间:2024/06/05 08:57
/*比较需要注意的是这句话*  Every line (except perhaps the last one) contains the initials of 80 cows ('A'..'Z') in the new line.  没有特殊处理格式的话,就很容易导致PE*/#include <iostream>using namespace std;int N;const int MAX_N = 2005;char S[MAX_N + 1];void solve(){//剩余字符串S[i]中,i的取值范围为[a,b] int a = 0, b = N - 1;int ans = 0;while (a <= b){//将从左起和从右起的字符串比较bool left = false;for (int i = 0; a + i <= b; i++){if ( S[a + i] < S[b - i] ){left = true;break;}else if ( S[a + i] > S[b - i] ){left = false;break;}}if (left) cout << S[a++];else cout << S[b--];ans++;if (ans % 80 == 0 && ans < N - 1) cout << endl; }cout << endl;}int main(){cin >> N;for (int i = 0; i < N; i++) cin >> S[i]; solve();return 0;}

原创粉丝点击