https://vjudge.net/problem/POJ-3617
这类字符串处理字典序问题经常用到贪心,
每决定输出一个字符之前,都要前后i++,j--逐个比大小,直至比出为止。
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
char a[];
int n;
int main()
{
cin >> n;
for(int i = ; i < n; i++){
cin >> a[i];
}
int st=, end=n-;
for(int i = ; i < n; i++){
int t=;
while(st+t<n&&end-t>=&&(a[st+t] == a[end-t])){//一直到比出大小为止
t++;
}
if(a[st+t] > a[end-t]){//取后
cout << a[end];
end--;
}
else if(a[st+t] < a[end-t]){
cout << a[st];
st++;
}
if((i+)%==) cout << endl;
}
return ;
}