一道初学者题目,“ 用1-9数字做不重复填充等式:_ _ _ _X_=_ _ _ _”

这是一道适合初学者的数学问题,通过编程实现用1到9的数字不重复地填充分解等式。示例代码展示了如何找出所有可能的乘积组合,满足等式中数字不重复且总数为10个。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// 乾坤一笑[smileonce]    smileonce@126.com   2004-7-23
// 版权所有 转载请注明出处  http://blog.youkuaiyun.com/smileonce
// math_t.cpp : Defines the entry point for the console application.
// 我来示范一下效率、正确性和易维护性的结合。 // 谁在丢砖头?我不是玻璃干吗砸我,我跑~~~ #include "stdafx.h" #include #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { set<int> num_set; for (int i=2; i<=9; i++) { int max_try = 9876 / i ; for (int j=1234; j<max_try; j++) { int k = i*j; if (k>10000) continue; num_set.clear(); num_set.insert(0); num_set.insert(i); num_set.insert(j/1000); num_set.insert(j/100%10); num_set.insert(j/10%10); num_set.insert(j%10); num_set.insert(k/1000); num_set.insert(k/100%10); num_set.insert(k/10%10); num_set.insert(k%10); if (num_set.size()==10) cout << j << " * " << i << " = " << k << endl; } } return 0; }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值