HDU ACM 4550 Card Game

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.