hawkj - 2005-7-30 17:46:00
#include <stdio.h>
#include <conio.h>
#define N 6
int a[N+1]={1,101,99,97,87,71,57},
b[N+1],results=0,mole;
int chess[N+1][20]={0};
void Find()
{ int i;
mole-=18;
for(i=1;i<=N;i++) b=mole/a;
}
void Comout()
{ int i,sum=0,j;
int d[N+1];
for(i=1;i<=N;i++)
for(j=1;j<=b;j++)
if(chess[j]!=0)
{ sum+=j*a;
d=j;
}
if(sum==mole)
{ for(i=1;i<=N;i++)
if(d!=0) printf("{%d,%d}",a,d);
results++;
}
}
void Searchans(int acidnum,int line)
{ int i,k;
if(acidnum>0)
{
for(i=1;i<=b;i++)
{ chess[line]=1;
/*k=acidnum-(i+1);*/
if((k=acidnum-(i+1))>=0)
{ Searchans(k,line+1);
chess[line]=0;
}
else
{ chess[line]=0;
Searchans(k,line+1);
break;
}
}
}
else Comout();
}
void Finals()
{ printf("ans is :%d",results);}
void Getmole()
{ printf("please enter the mole:");
scanf("%d",&mole);
/*printf("mole is %d\n",mole);*/
}
void main()
{ int i,line,j;
clrscr();
Getmole();
Find();
for(j=1;j<=N;j++) if(b[j]!=0) line=j;
for(i=b[1];i<=b[N];i++)
{
Searchans(i,line);
}
Finals();
}
hawkj - 2005-7-30 17:53:00
救命
wzjan - 2005-7-31 9:09:00
wo bang ni wei wo laoshi l
gu jitian gaoshu ni daan
清风阁☆四少 - 2005-7-31 11:13:00
********************
printf("{%d,%d}",a,d); ????
del {}
********************************
© 2000 - 2024 Rising Corp. Ltd.