2013年第四届蓝桥杯C/C++ A组国赛 —— 第一题:填算式
标题:填算式
请看下面的算式:
(ABCD - EFGH) * XY = 900
每个字母代表一个0~9的数字,不同字母代表不同数字,首位不能为0。
比如,(5012 - 4987) * 36 就是一个解。
请找到另一个解,并提交该解中 ABCD 所代表的整数。
请严格按照格式,通过浏览器提交答案。
注意:只提交 ABCD 所代表的整数,不要写其它附加内容,比如:说明性的文字。
Code
/*
^....0
^ .1 ^1^
.. 01
1.^ 1.0
^ 1 ^ ^0.1
1 ^ ^..^
0. ^ 0^
.0 1 .^
.1 ^0 .........001^
.1 1. .111100....01^
00 11^ ^1. .1^
1.^ ^0 0^
.^ ^0..1
.1 1..^
1 .0 ^ ^
00. ^^0.^
^ 0 ^^110.^
0 0 ^ ^^^10.01
^^ 10 1 1 ^^^1110.1
01 10 1.1 ^^^1111110
010 01 ^^ ^^^1111^1.^ ^^^
10 10^ 0^ 1 ^^111^^^0.1^ 1....^
11 0 ^^11^^^ 0.. ....1^ ^ ^
1. 0^ ^11^^^ ^ 1 111^ ^ 0.
10 00 11 ^^^^^ 1 0 1.
0^ ^0 ^0 ^^^^ 0 0.
0^ 1.0 .^ ^^^^ 1 1 .0
^.^ ^^ 0^ ^1 ^^^^ 0. ^.1
1 ^ 11 1. ^^^ ^ ^ ..^
^..^ ^1 ^.^ ^^^ .0 ^.0
0..^ ^0 01 ^^^ .. 0..^
1 .. .1 ^.^ ^^^ 1 ^ ^0001
^ 1. 00 0. ^^^ ^.0 ^.1
. 0^. ^.^ ^.^ ^^^ ..0.0
1 .^^. .^ 1001 ^^ ^^^ . 1^
. ^ ^. 11 0. 1 ^ ^^ 0.
0 ^. 0 ^0 1 ^^^ 0.
0.^ 1. 0^ 0 .1 ^^^ ..
.1 1. 00 . .1 ^^^ ..
1 1. ^. 0 .^ ^^ ..
0. 1. .^ . 0 .
.1 1. 01 . . ^ 0
^.^ 00 ^0 1. ^ 1 1
.0 00 . ^^^^^^ .
.^ 00 01 ..
1. 00 10 1 ^
^.1 00 ^. ^^^ .1
.. 00 .1 1..01 ..
1.1 00 1. ..^ 10
^ 1^ 00 ^.1 0 1 1
.1 00 00 ^ 1 ^
. 00 ^.^ 10^ ^^
1.1 00 00 10^
..^ 1. ^. 1.
0 1 ^. 00 00 .^
^ ^. ^ 1 00 ^0000^ ^ 01
1 0 ^. 00.0^ ^00000 1.00.1 11
. 1 0 1^^0.01 ^^^ 01
.^ ^ 1 1^^ ^.^
1 1 0.
.. 1 ^
1 1
^ ^ .0
1 ^ 1
.. 1.1 ^0.0
^ 0 1..01^^100000..0^
1 1 ^ 1 ^^1111^ ^^
0 ^ ^ 1 1000^
.1 ^.^ . 00
.. 1.1 0. 0
1. . 1. .^
1. 1 1. ^0
^ . ^.1 00 01
^.0 001. .^
*/
// VB_king —— 2013_Finals_A_C++_1.cpp created by VB_KoKing on 2019-05-09:10.
/* Procedural objectives:
Variables required by the program:
Procedural thinking:
Functions required by the program:
Determination algorithm:
Determining data structure:
*/
/* My dear Max said:
"I like you,
So the first bunch of sunshine I saw in the morning is you,
The first gentle breeze that passed through my ear is you,
The first star I see is also you.
The world I see is all your shadow."
FIGHTING FOR OUR FUTURE!!!
*/
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int num[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
do {
if (num[0] == 0 || num[4] == 0 || num[8] == 0) continue;
int ABCD = num[0] * 1000 + num[1] * 100 + num[2] * 10 + num[3];
int EFGH = num[4] * 1000 + num[5] * 100 + num[6] * 10 + num[7];
int XY = num[8] * 10 + num[9];
if ((ABCD - EFGH) * XY == 900) {
cout << '(' << ABCD << " - " << EFGH << ')' << " * " << XY << " = " << (ABCD - EFGH) * XY << endl;
cout << "ABCD=" << ABCD << endl;
}
} while (next_permutation(num, num + 10));
return 0;
}