POJ 3617 Best Cow Line

//题目链接:http://poj.org/problem?id=3617
#include <iostream> using namespace std; int n; char s[2010]; int main() { while (cin >> n) { int count = 0; for (int i = 0; i < n; i++) { cin >> s[i]; } int a = 0, b = n - 1; 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) putchar(s[a++]); else putchar(s[b--]); count++; if (count % 80 == 0) putchar('\n'); } putchar('\n'); } return 0; }

 

posted on 2018-08-08 16:38  Misko  阅读(107)  评论(0编辑  收藏  举报