poj3617(字典序最小問題)
#include
#include
#include
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<