算法:用1-9数字做不重复填充:_ _ _ _X_=_ _ _ _

852阅读 0评论2008-10-13 UGxxoVr
分类:

/************************************************************************/
/*  use number 0~9 fill expresstion ____ X_ = ____                     */
/*  author : smileonce                                                  */
/************************************************************************/
// 我来示范一下效率、正确性和易维护性的结合。
// 谁在丢砖头?我不是玻璃干吗砸我,我跑~~~

#include "stdafx.h"
#include 
#include 
using namespace std;

int main(int argc, char** 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;                   
            
            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;
}

--------------------next---------------------

上一篇:求素数的爱沙托散筛法
下一篇:程序设计的智力推测:1 11 21 1211 111221 ____