ACM 10905 Q10905: Children’s Game
作法 : 說真的,我不曉得別人怎麼寫得那麼短
我的作法 "非常"的長
可以參考我在 第二題:排列最大值 的說明 (我沒連結 自己去看唄)
/****************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
int a,b,c,n,mm;
while(scanf("%d",&n)==1&&n!=0)
{
char x[100];
int math[101][100],number[100]={0};
for(a=0;a<n;a++)
{
scanf("%s",x);
int m=strlen(x);
number[a]=m;
for(b=0,c=0;b<100;b++,c++)
{
math[a][b]=x[c];
if(c==m-1)
c=-1;
}
}
for(a=0;a<n;a++)
for(b=0;b<n-1;b++)
{
int flag=0;
for(c=0;c<100;c++)
{
if(math[b][c]>math[b+1][c])/*找到前面的比較大 不用動*/
{flag=0;break;}
if(math[b+1][c]>math[b][c])
{flag=1;break;}
}
if(flag==1)
{
int temp,temp1[100];
for(c=0;c<100;c++)
{
temp1[c]=math[b][c];
math[b][c]=math[b+1][c];
math[b+1][c]=temp1[c];
}
temp=number[b];
number[b]=number[b+1];
number[b+1]=temp;
}
}
for(a=0;a<n;a++)
for(b=0;b<number[a];b++)
printf("%c",math[a][b]);
printf("\n");
}
return 0;
}