#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,m;
char S[2100],P[2100];
int main()
{
#ifdef xxz
freopen("in.txt","r",stdin);
#endif // xxz
ios::sync_with_stdio(false);
cin.tie(0);
int sum = 0;
while(cin>>n)
{
for(int i = 0; i < n; i++) cin>>S[i];
int a = 0, b = n-1,cent = 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) P[cent++] = S[a++];
else P[cent++] = S[b--];
}
for(int i = 0; i < n; i++)
{
sum += 1;
cout<<P[i];
if(sum%80 == 0 && i != n-1) cout<<endl;
}
}
return 0;
}
poj3617(字典序最小问题)
最新推荐文章于 2020-05-08 11:11:57 发布