古堡算式代码:
# include <stdio.h>
int main(){int a, b, c, d, e;int x;int left, right;left = a * 10000 + b * 1000 + c * 100 + d * 10 + e * 1;right = e * 10000 + d * 1000 + c * 100 + b * 10 + a * 1;for(a = 0; a <= 9; a++){for(b = 0; b <= 9; b++){for(c = 0; c <= 9; c++){for(d = 0; d <= 9; d++){for(e = 0; e <= 9; e++){for(x = 0; x <= 9; x++){left = a * 10000 + b * 1000 + c * 100 + d * 10 + e * 1;right = e * 10000 + d * 1000 + c * 100 + b * 10 + a * 1;if(left * x == right && a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e ){printf("%d %d %d %d %d\n", a, b, c, d, e);}}}}}}}return 0;
}
四个数字代码:
#include <iostream>
#include <algorithm>using namespace std;int main() {int a,b,c,d,answer,count=0 , count1 = 0 ;int org[4];int ans[4];for(a = 0; a<10 ; a++){for(b = 0 ; b < 10; b++){for(c = 0 ; c < 10 ; c++){for (d = 0 ; d < 10 ; d++){if(a!= b && a!=c && a!=d && b!=c && b!=d && c!=d){org[0] = a; org[1] = b ; org[2] = c; org[3] = d;sort(org,org+4);answer = a *(b*100+c*10+d);if(answer >1000 && answer < 9999){ans[0] = answer%10; answer = answer/10;ans[1] = answer%10; answer = answer/10;ans[2] = answer%10; answer = answer/10;ans[3] = answer%10;sort(ans,ans+4);for (int i = 0; i < 4; ++i) {if (ans[i] != org[i]){break;}if(i == 3){cout<<a<<" " <<b<<c<<d<<endl;count++;}}}}}}}}for(a = 0; a<10 ; a++){for(b = 0 ; b < 10; b++){for(c = 0 ; c < 10 ; c++){for (d = 0 ; d < 10 ; d++){if(a!= b && a!=c && a!=d && b!=c && b!=d && c!=d){org[0] = a; org[1] = b ; org[2] = c; org[3] = d;sort(org,org+4);answer = (a*10+b)*(c*10+d);if(answer >1000 && answer < 9999){ans[0] = answer%10; answer = answer/10;ans[1] = answer%10; answer = answer/10;ans[2] = answer%10; answer = answer/10;ans[3] = answer%10;sort(ans,ans+4);for (int i = 0; i < 4; ++i) {if (ans[i] != org[i]){break;}if(i == 3) {cout<<a<<b<<" "<<c<<d<<endl;count1++;}}}}}}}}cout<< count+(count1/2);
}
艺术品专卖店代码:
#include <iostream>
using namespace std;
int main() {int propNum[7] = {0,1,2,5,6,8,9};int org_E= 0 , exc_E = 0 , org_T = 0 , exc_T = 0;//转换签的数字,转换后的数字 int a,b,c,d;//四个数字,四重循环 for (int i = 1; i < 7; ++i) {a = propNum[i];for (int j = 0; j < 7; ++j) {b = propNum[j];for (int k = 0; k < 7; ++k) {c = propNum[k];for (int l = 1; l < 7; ++l) {d = propNum[l];org_E = a*1000+b*100+c*10+d;//构建数字调整6与9 if (a==6 || a==9){if (a == 6) a=9;else a = 6 ;}if (b==6 || b==9){if (b == 6) b=9;else b = 6 ;}if (c==6 || c==9){if (c == 6) c=9;else c = 6 ;}if (d==6 || d==9){if (d == 6) d=9;else d = 6 ;}exc_E = d*1000+c*100+b*10+a;//翻转数字,按照题目给的条件缩小范围 if(exc_E - org_E > 800 && exc_E-org_E <900){// cout << org_E<<" "<<exc_E<<endl;//寻找另外一个数 for (int m = 1; m < 7; ++m) {a = propNum[m];for (int n = 0; n < 7; ++n) {b = propNum[n];for (int i1 = 0; i1 < 7; ++i1) {c = propNum[i1];for (int j1 = 1; j1 < 7; ++j1) {d = propNum[j1];org_T = a*1000+b*100+c*10+d;if (a==6 || a==9){if (a == 6) a=9;else a = 6 ;}if (b==6 || b==9){if (b == 6) b=9;else b = 6 ;}if (c==6 || c==9){if (c == 6) c=9;else c = 6 ;}if (d==6 || d==9){if (d == 6) d=9;else d = 6 ;}exc_T = d*1000+c*100+b*10+a;if(org_T-exc_T > 200 && org_T-exc_T<300){if((exc_E - org_E)-(org_T-exc_T)==558){cout << org_T;return 0;}}}}}}}}}}}
}