1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 int main() 5 { 6 int n; 7 char s1[2020],s2[2020]; 8 scanf("%d",&n); 9 for (int i=0;i<n;i++) 10 { 11 char ch; 12 scanf(" %c",&ch); 13 s1[i]=ch; 14 } 15 int l=0,r=n-1,p=0; 16 while (l<=r) 17 { 18 bool left=false; 19 for (int i=0;l+i<=r;i++) 20 { 21 if (s1[l+i]<s1[r-i]) 22 { 23 left=true; 24 break; 25 }else if (s1[l+i]>s1[r-i]) 26 { 27 left=false; 28 break; 29 } 30 } 31 if (left) s2[p]=s1[l++]; 32 else s2[p]=s1[r--]; 33 p++; 34 } 35 for (int i=0;i<n;i++) 36 { 37 printf("%c",s2[i]); 38 if ((i+1)%80==0) printf("\n"); 39 } 40 printf("\n"); 41 return 0; 42 }
时间: 2024-12-21 14:34:57