UVa 10905 - Children's Game

来源:互联网 发布:简易电气画图软件 编辑:程序博客网 时间:2024/04/29 16:30
/*  就是一些数字字符串 ,怎样排序让组成的数字最大   贪心: 每次选两个字符串组成的数大的放在前面就行了 */ #include<stdio.h>#include<string.h>#include<iostream>using namespace std;//int str[55][1000];struct node{    char str[128];      // int len;}ss[57];bool cmp(node a,node b){   char s1[128]={'\0'};   char s2[128]={'\0'};      strcpy(s1,a.str);   strcat(s1,b.str);      strcpy(s2,b.str);   strcat(s2,a.str);      if(strcmp(s1,s2)>0)     return true;   return false;}void Qsort(int x,int y){    if(x>=y) return ;        int p=x,q=y;        node f=ss[x];        while(p<q)    {      while(p<q && !cmp(ss[q],f))            q--;      if(p<q)        ss[p++]=ss[q];              while(p<q && cmp(ss[p],f))  /// 快排这里写错了 搞了半天 自己出的几组数据太弱了 居然还过了             p++;        if(p<q)          ss[q--]=ss[p];         }   ss[p]=f;      Qsort(x,p-1);   Qsort(p+1,y);}int main(){    int n,i;    //node a,b;    // a.str={"1234"};    // b.str={"45"};    /*while(1)    {    scanf("%s",&a.str);    scanf("%s",&b.str);    printf("%d+++\n",cmp(a,b));    }*/        while(scanf("%d",&n)!=EOF)    {       if(n==0)  break;              for(i=0;i<n;i++)       {         scanf("%s",ss[i].str);        //ss[i].len=strlen(ss[i].str);         }       Qsort(0,n-1);              for(i=0;i<n;i++)       printf("%s",ss[i].str);              printf("\n");                                                }     return 0;    }/*4123 124 56 902 191 192 9909 990*/