Analysis: Divided into three parts processing, the first part found in addition to 0 the most right of the smallest number A as the first, the second part of the smallest number a in front of the numbers are arranged according to the rules, that is, each take out a large in the second part of the back, small placed in front of the second part The third part is that the number after the minimum number A is placed in the last order, and the new string is eventually set.
Example:9876105432.
First part: 1
Part II: 9876, 6789 after processing
Part III: 05432
Finally, according to the first part, the second part, the third part of the sequence of the new string: 1678905432 is the final result.
#include <iostream>using namespace Std;int main () {int T,i,minnum,minindex,j,k;char A[105];char b[305];cin> >t;getchar (); while (t--) {gets (a); Minnum=100;for (I=strlen (a) -1;i>=0;i--) if (a[i]<minnum && a[i]!= ' 0 ') {minnum=a[i];minindex=i;} if (minnum==100) minnum=a[0];b[0]=minnum;j=-2;k=-1;if (strlen (a) >=2) {if (minindex!=0) {k=j=150;b[k]=a[0];for (i=1 ; i<minindex;i++) if (B[k]>=a[i]) { k--; B[k]=a[i];} else{ j + +; B[j]=a[i];}}} Putchar (B[0]), for (i=k;i<=j;i++) Putchar (B[i]), for (I=minindex+1;i<strlen (a); i++) Putchar (A[i]);cout<< Endl;} return 0;}
HDU ACM 4550 Card Game