题目描述:
福尔摩斯到某古堡探险,看到门上写着一个奇怪的算式:
ABCDE * ? = EDCBA
他对华生说:“ABCDE应该代表不同的数字,问号也代表某个数字!”
华生:“我猜也是!”
于是,两人沉默了好久,还是没有算出合适的结果来。
请你利用计算机的优势,找到破解的答案。
把 ABCDE 所代表的数字写出来。
答案写在“解答.txt”中,不要写在这里!
题目答案:
21978
题目思路:
ABCDE?这五个字符分别代码不同的数字(0-9中),将所有可能的情况枚举出来,找到符合的答案即可。可以用next_permutation()函数加快做题的速度。
题目代码:
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- int a[10] = {0,1,2,3,4,5,6,7,8,9};
- int main(){
- do{
-
- int x1 = a[0]*10000+a[1]*1000+a[2]*100+a[3]*10+a[4];
- int x2 = a[5];
- int x3 = a[0]+a[1]*10+a[2]*100+a[3]*1000+a[4]*10000;
- if(x1*x2==x3){
- printf("%d * %d = %d\n",x1,x2,x3);
- }
- }while(next_permutation(a,a+10));
- return 0;
- }
题目描述:
如图【1.png】所示六角形中,填入1~12的数字。
使得每条直线上的数字之和都相同。
图中,已经替你填好了3个数字,请你计算星号位置所代表的数字是多少?
请通过浏览器提交答案,不要填写多余的内容。
题目答案:
10
题目思路:
用一个数组,存储每个位置上的数值,枚举全排列,判断符合条件的情况即可。
题目代码:
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- int a[12] = {1,2,3,4,5,6,7,8,9,10,11,12};
- int main(){
- do{
- int x1 = a[0]+a[2]+a[5]+a[7];
- int x2 = a[0]+a[3]+a[6]+a[10];
- int x3 = a[7]+a[8]+a[9]+a[10];
- int x4 = a[1]+a[2]+a[3]+a[4];
- int x5 = a[1]+a[5]+a[8]+a[11];
- int x6 = a[4]+a[6]+a[9]+a[11];
- if(a[0]==1&&a[1]==8&&a[11]==3&&x1==x2&&x2==x3&&x3==x4&&x4==x5&&x5==x6){
- printf("%d\n",a[5]);
- }
-
- }while(next_permutation(a,a+12));
-
-
- return 0;
- }