For more articles, please pay attention to the official account of "BLOG of the sea".
problem
Observe the following addition formula:
Auspicious life +Sanyang presents Rui ---------------- Sanyang is lucky
Among them, the same Chinese character represents the same number, different Chinese characters represent different numbers, and "three" and "Xiang" cannot be 0. Please figure out what the four digits represented by "sanyangxianrui". (unique answer)
Note: you should submit an integer. Do not fill in any extra content or explanatory text. Do not wrap at the end of the line.
thinking
I used violence to solve this problem
Implementation code
#include<stdio.h> int main(){ int x,r,s,h,san,yan,xian,qi,sum1,sum2,sum3; for (x=1; x<=9;x++) { for (r=0; r<=9; r++) { for (s=0; s<=9; s++) { for (h=0; h<=9; h++) { for (san=1; san<=9; san++) { for (yan=0; yan<=9; yan++) { for (xian=0; xian<=9; xian++) { for (qi=0; qi<=9; qi++) { sum1=x*1000+r*100+s*10+h; sum2=san*1000+yan*100+xian*10+r; sum3=san*10000+yan*1000+s*100+r*10+qi; if (sum1+sum2==sum3 && x!=r && x!=s && x!=h && x!=san && x!=yan && x!=xian && x!=qi && r!=s && r!=h && r!=san && r!=h && r!=san && r!=yan && r!=xian && r!=qi &&s!=h && s!=san && s!=yan && s!=xian && s!=qi &&h!=san &&h!=yan &&h!=xian && h!=qi &&san!=yan &&san!=qi&& yan!=xian && yan!=qi &&xian!=qi) { printf("%d+%d=%d\n",sum1,sum2,sum3); } } } } } } } } } }
For more articles, please pay attention to the official account of "BLOG of the sea".