三羊献瑞~
三羊献瑞观察下面的加法算式:
祥 瑞 生 辉
+ 三 羊 献 瑞
-------------------
三 羊 生 瑞 气
如果有对其问题可以参考图片~
其中,相同的汉字代表相同的数字,不同的汉字代表不同的数字。
请你填写“三羊献瑞”所代表的4位数字(答案唯一),不要填写任何多余内容。
我还是先少说话了……看看这题感觉如何~
[此贴子已经被作者于2017-10-22 23:02编辑过]
[此贴子已经被作者于2017-10-22 23:02编辑过]
#include<stdio.h> int main() { int xiang = 0, rui = 0, sheng = 0, hui = 0, san = 0, xian = 0, qi = 0,yang = 0; int beijia = 0, jia = 0, he = 0; for (xiang = 8; xiang <= 9; xiang++) { for (san = 1; san <= 1; san++) { for (yang = 0; yang <= 1; yang++) { for (hui = 0; hui <= 9; hui++) { for (rui = 0; rui <= 9; rui++) { for (xian = 0; xian <= 9; xian++) { for (sheng = 0; sheng <= 9; sheng++) { for (qi = 0; qi <= 9; qi++) { beijia = xiang * 1000 + rui * 100 + sheng * 10 + hui; jia = san * 1000 + yang * 100 + xian * 10 + rui; he = san * 10000 + yang * 1000 + sheng * 100 + rui * 10 + qi; if (beijia + jia == he) { if ((xiang != rui) && (xiang != sheng) && (xiang != hui) && (xiang != san) && (xiang != xian) && (xiang != qi) && (xiang != yang) && (rui != sheng) && (rui != hui) && (rui != san) && (rui != xian) && (rui != qi) && (rui != yang) && (sheng != hui) && (sheng != hui) && (sheng != san) && (sheng != xian) && (sheng != qi) && (sheng != yang) && (hui != san) && (hui != xian) && (hui != qi) && (hui != yang) && (san != xian) && (san != qi) && (san != yang) && (xian != qi) && (xian != yang) && (qi != yang)) { //printf("%d%d%d%d\n", xiang, rui, sheng, hui); printf("%d%d%d%d\n", san, yang, xian, rui); //printf("%d%d%d%d%d\n", san, yang, sheng, rui, qi); } } } } } } } } } } return 0; }
[此贴子已经被作者于2017-10-23 11:02编辑过]
#include <stdio.h> int pd(int,int,int); void main() { int i,j,k; for(i=1023;i<2000;i++) { for(j=9876;j>8000;j--) { k=i+j; if(pd(j,i,k)) { printf(" %d\n+%d\n------\n%d\n",j,i,k); return; } } } } int pd(int x,int y,int z) { int i,j,a[8],b[5],d[10]={0}; if(z<10000)return 0; for(j=0,i=x*10000+y;i;i/=10) { d[i%10]=1; a[j++]=i%10; } for(i=j=0;i<10;i++)j+=d[i]; if(j!=7)return 0; for(j=0,i=z;i;i/=10) { d[i%10]=1; b[j++]=i%10; } for(i=j=0;i<10;i++)j+=d[i]; return j==8&&a[0]==a[6]&&a[0]==b[1]&&a[5]==b[2]&&a[2]==b[3]&&a[3]==b[4]; }