You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
782 B
37 lines
782 B
#include <iostream>
|
|
using namespace std;
|
|
const int N = 2010;
|
|
char s[N];
|
|
|
|
int main() {
|
|
int n;
|
|
cin >> n;
|
|
for (int i = 0; i < n; i++) cin >> s[i];
|
|
|
|
int a = 0, b = n - 1, idx = 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;
|
|
}
|
|
if (s[a + i] > s[b - i]) {
|
|
left = false;
|
|
break;
|
|
}
|
|
}
|
|
if (left)
|
|
putchar(s[a++]);
|
|
else
|
|
putchar(s[b--]);
|
|
idx++;
|
|
|
|
if (idx == 80) {
|
|
idx = 0;
|
|
puts("");
|
|
}
|
|
}
|
|
return 0;
|
|
} |