分析:控制每个字不能相等,和那些数可以相等
#include<iostream> #include<stdio.h> int main() { int t1,t2,t3,t4; int m1,m2,m3,m4; int n1,n2,n3,n4,n5; int sum=0; for(int i=1000;i<9999;i++) { t1=i%10; t2=i/10%10; t3=i/100%10; t4=i/1000; if(t1!=t2&&t1!=t3&&t1!=t4&&t2!=t3&&t2!=t4&&t3!=t4) { for(int j=1000;j<9999;j++) { m1=j%10; m2=j/10%10; m3=j/100%10; m4=j/1000; if(m1!=m2&&m1!=m3&&m1!=m4&&m2!=m3&&m2!=m4&&m3!=m4) { sum=i+j; n1=sum%10; n2=sum/10%10; n3=sum/100%10; n4=sum/1000%10; n5=sum/10000; if(t1!=m2&&m1!=t2&&m2!=n3&&t1!=m1&&t3==n2&&t3==m1&&n5!=n1&&n1!=n2&&n1!=n3&&n1!=n4&&n2!=n3&&n2!=n4&&n3!=n4&&n5==m4&&n4==m3&&n3==t2&&n2==m1&&n2==t3&&m1==t3&&t4!=m1&&t4!=m2) { printf("%d %d %d\n",i,j,sum); } } } } } return 0; }