第九周项目6 求墨水遮住的数字问题

来源:互联网 发布:网络教育几月份报名 编辑:程序博客网 时间:2024/04/30 01:52

问题及代码:

/* *copyright (c) 2014,烟台大学计算机学院 *all rights reserved. *文 件 名 : 求墨水遮住的数字 .cpp *作    者 :张   鹏 *完成日期 :2014年10月27号 *版 本 号 :v1.1 * *问题描述 :有等式[※×(※3O※)]^2=8※※9,其中※处为一个数字,O为一个运算符号滴上了墨水无法辨认。请编程找出※是那些数字。 *输入描述 :无 *程序输出 :输出原等式。 */#include <iostream>                                       //预处理指令。#include <cmath>                                          //使用数学符号。using namespace std;                                      //使用C++的命名空间 std。int main()                                                //函数首部。{    int iFirst,iSecond,iThird,iFourth,iFifth,iCase=1;     //声明六个变量iFirst,iSecond,iThird,iFourth,iFifth,iCase为整型。    cout<<"原式可能是:"<<endl;                           //输出汉字,使得界面更友好。    for (iFirst=0; iFirst<=9; iFirst++)                   //穷举第一个※数字的可能性,下同。        for (iSecond=0; iSecond<=9; iSecond++)            for (iThird=0; iThird<=9; iThird++)                for (iFourth=0; iFourth<=9; iFourth++)                    for (iFifth=0; iFifth<=9; iFifth++)                    {                        if ((iFirst*(iSecond*10+3+iThird)*iFirst*(iSecond*10+3+iThird)==8000+iFourth*100+iFifth*10+9))//判断是否符合条件。                        {                            cout<<"情况"<<iCase++<<": [";                            cout<<iFirst<<"×("<<iSecond<<"3+";                            cout<<iThird<<")]^2=8"<<iFourth<<iFifth<<"9"<<endl;                        }                    }    return 0;                                               //执行retur语句,结束程序。}

运行结果:


知识点总结:

  for语句的利用。

学习心得:

  编程能够快速的解决奥数问题,真棒!

0 0