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

王朝other·作者佚名  2006-01-09
宽屏版  字体: |||超大  

// 乾坤一笑[smileonce] smileonce@126.com 2004-7-23

// 版权所有 转载请注明出处 http://blog.csdn.net/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;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有