游客 Signup | Login
中文 | En

3539 - 填算式(蓝桥杯真题)

    看这个算式:
    ☆☆☆ + ☆☆☆ = ☆☆☆
    如果每个五角星代表 1 ~ 9 的不同的数字。
    这个算式有多少种可能的正确填写方法?
    173 + 286 = 459
    295 + 173 = 468
    173 + 295 = 468
    183 + 492 = 675
    以上都是正确的填写法!
    注意:
    111 + 222 = 333 是错误的填写法!
    因为每个数字必须是不同的!
    也就是说:1~9中的所有数字,每个必须出现且仅出现一次!
    注意:
    不包括数字“0”!
    注意:
    满足加法交换率的式子算两种不同的答案。
    所以答案肯定是个偶数!

Input

 

Output

Examples

Input


                

Output


                

Solution C++

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int p[9]={1,2,3,4,5,6,7,8,9};
	int cnt=0;
	do
	{
		if((p[0]*100+p[1]*10+p[2]+p[3]*100+p[4]*10+p[5])==(p[6]*100+p[7]*10+p[8]))
			cnt++;	
	}while(next_permutation(p,p+9));
	cout<<cnt;
	return 0;
}

Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题