没做完,先搞答题了
#include#include #include int comp(const void *a,const void *b){ return *(int*)a-*(int*)b;}int main(){ //----part1 for(int i=100;i<=999;i++) { int a[4]; memset(a,0,sizeof(a[0])); a[0]=i/100; a[1]=i/10%10; a[2]=i%10; for(a[3]=0;a[3]<=9;a[3]++) { //a not equal to each other if(a[0]!=a[1]&&a[0]!=a[2]&&a[0]!=a[3]&&a[1]!=a[2]&&a[1]!=a[3]&&a[2]!=a[3]) { int sum=i*a[3]; if(sum>1000&&sum<9999) { int b[4]; memset(b,0,sizeof(b[0])); b[0]=sum/1000; b[1]=sum/100%10; b[2]=sum/10%10; b[3]=sum%10; //b not equal to each other if(b[0]!=b[1]&&b[0]!=b[2]&&b[0]!=b[3]&&b[1]!=b[2]&&b[1]!=b[3]&&b[2]!=b[3]) { qsort(a,4,a[0],comp); } } } } } //--part2 for(;;) { }}
d
运行无答案
#includeint main(){ int a[8]; for(a[0]=1;a[0]<=4;a[0]++) { for(a[1]=1;a[1]<=4;a[1]++) { for(a[2]=1;a[2]<=4;a[2]++) { for(a[3]=1;a[3]<=4;a[3]++) { for(a[4]=1;a[4]<=4;a[4]++) { for(a[5]=1;a[5]<=4;a[5]++) { for(a[6]=1;a[6]<=4;a[6]++) { for(a[7]=1;a[7]<=4;a[7]++) { for(int i=0;i<=7;i++) { int count1=0,count2=0,count3=0,count4=0; if(a[i]==1)count1++; if(a[i]==2)count2++; if(a[i]==3)count3++; if(a[i]==4)count4++; int dist1=0,dist2=0,dist3=0,dist4=0; if(count1==2&&count2==2&&count3==2&&count4==2) { for(int j=0;j<=7;j++) { int node11=0,node12=0; int node21=0,node22=0; int node31=0,node32=0; int node41=0,node42=0; if(a[j]==1&&node11) { node12=j; dist1=node12-node11; } if(a[j]==2&&node21) { node22=j; dist2=node22-node21; } if(a[j]==3&&node31) { node32=j; dist3=node32-node31; } if(a[j]==4&&node41) { node42=j; dist4=node42-node41; } if(a[j]==1) { node11=j; } if(a[j]==2) { node21=j; } if(a[j]==3) { node31=j; } if(a[j]==4) { node41=j; } } if(dist1==1&&dist2==2&&dist3==3&&dist4==4) printf("%d%d%d%d%d%d%d%d",a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]); } else break; } } } } } } } } }}