#define N 1000
void sort(int a[],int n);
void chazhao(int a[],int low,int high);
void chongfu(int n);
main()
{ int n;
scanf("%d",&n);
while(n)
{
chongfu(n);
scanf("%d",&n);
}
}
void sort(int a[],int n)
{int i,j,k;
int temp;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[j]<a[i])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
}
void chazhao(int a[],int low,int high)
{
int i,j,a1[5],a2[5],k,flag;
for(i=low;i<high-1;i++)
{ if(a[i]!=0)
{
a1[0]=a[i]/10000;
a1[1]=a[i]%10000/1000;
a1[2]=a[i]%1000/100;
a1[3]=a[i]%100/10;
a1[4]=a[i]%10;
sort(a1,5);
flag=0;
for(j=i+1;j<high;j++)
{
a2[0]=a[j]/10000;
a2[1]=a[j]%10000/1000;
a2[2]=a[j]%1000/100;
a2[3]=a[j]%100/10;
a2[4]=a[j]%10;
sort(a2,5);
if(a1[0]==a2[0]&&a1[1]==a2[1]&&a1[2]==a2[2]&&a1[3]==a2[3]&&a1[4]==a2[4])
{a[j]=0; flag=1;}
}
if(flag)
a[i]=0;
}
}
}
void chongfu(int n)
{
int i,j,wei[5]={0,0,0,0,0},a[N];
for(i=0;i<n;i++)
{scanf("%d",&a[i]);
}
sort(a,n);
for(i=0;i<n;i++)
{if(a[i]/10==0)
wei[0]++;
else if(a[i]/100==0)
wei[1]++;
else if(a[i]/1000==0)
wei[2]++;
else if(a[i]/10000==0)
wei[3]++;
else
wei[4]++;
}
for(i=0;i<5;i++)
chazhao(a,0,wei[0]);
chazhao(a,wei[0],wei[0]+wei[1]);
chazhao(a,wei[0]+wei[1],wei[0]+wei[1]+wei[2]);
chazhao(a,wei[0]+wei[2],wei[0]+wei[1]+wei[2]+wei[3]);
chazhao(a,wei[0]+wei[1]+wei[2]+wei[3],n);
j=1;
for(i=0;i<n;i++)
{
if(a[i]!=0)
{j=0;break;}
}
if(j)
{
printf("\nNone");
}
printf("\n");
for(i=0;i<n;i++)
{ if(a[i]!=0)
printf("%-5d ",a[i]);
}
}
不知道行不行?
[此贴子已经被作者于2006-11-26 21:09:34编辑过]