第九周项目六 求墨水遮住数字问题之变式

问题及代码:

/*
 *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()                                                //函数首部。
{
    double 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;      //当O为+的时候。
                        }
                        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;      //当O为-的时候。
                        }
                        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;       //当O为*的时候。
                        }
                        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;       //当O为/的时候。
                        }



                    }
    return 0;                                               //执行retur语句,结束程序。
}


运行结果:


知识点总结:

  当o为÷号时要定义为double不然数据溢出,跑不出来。

学习心得:

  多亏了学长提醒才知道把int改double,看来编程之路上我还是一个小菜鸟。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值