• 穷举算法,遍历所有情况


    转载:https://blog.csdn.net/guugle2010/article/details/40816023

    填数字游戏

    代码:

    #include<iostream>
    int main()
    {
      using namespace std;
      int t1,t2,t3,t4,t5;
      for (t1=1; t1<=9; t1++)
      {
        for(t2=0; t2<=9; t2++)
        {
          for(t3=0; t3<=9; t3++)
          {
            for(t4=0; t4<=9; t4++)
            {
              for(t5=0; t5<=9; t5++)
              {
                if(t5*100000 + t5*10000 + t5*1000 + t5*100 + t5*10 + t5 == t5*t1 + t4*t1*10 + t3*t1*100 + t2*t1*1000 + t1 *t1*10000 )
                {
                  cout << " 算的数值为: " << t1 << " 法的数值为: " << t2 << " 描的数值为: " <<t3 << " 述的数值为: " << t4 << " 题的数值为: " << t5<<endl;
                  cout << " " << t1 << " " << t2 << " " << t3 << " " << t4 << " " << t5 <<endl;
                  cout << "X " << t1<<endl;
                  cout << "________________ ";
                  cout << " " << t5 << " " << t5 << " " << t5 << " " << t5 << " " << t5 << " " << t5 <<endl;
                }
              }
            }
          }
        }
      }
      return 0;
    }
    运行结果:

    ————————————————

    版权声明:本文为CSDN博主「guugle2010」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/guugle2010/article/details/40816023

  • 相关阅读:
    MyBatis3系列__01HelloWorld
    localStorage、sessionStorage、Cookie的区别及用法
    Javascript数组原型方法大全以及实例!!
    如何使用正则表达式以及封装函数?
    收藏多年的正则表达式笔记大全,绝对是干货!
    手写Ajax的意义所在,从青铜到钻石!
    Git的常用命令
    阿里云部署服务器流程
    MongoDB常用数据库命令第二集
    vuex简单化理解和安装使用
  • 原文地址:https://www.cnblogs.com/cy1993/p/11436250.html
Copyright © 2020-2023  润新知