蓝桥杯模拟赛 猜算式

第一次参加比赛,感觉之前学的好多东西都不知道怎么用,感觉准备很不充分。但是我还是想去拼一下,大不了明年接着刷,保研保本校跟着院长混。

废话不说,直接发出代码。暴力破解,其中代码块复制粘贴了很多,很容易的思路。通俗易懂。
由于我之前做过不少工程项目,我非常不习惯竞赛当中毫无意义的变量,这玩意遇到难题给你代码你都看不懂。非常爆炸。但也是我修为尚浅,继续努力吧。和CSDN诸君共勉。

#include <iostream>
using namespace std;
int numTimes[10];

void Initial()
{
    for (int i = 0; i < 10; i++)
    {
        numTimes[i] = 0;
    }
}

bool check()
{
    for (int i = 0; i < 10; i++)
    {
        if (numTimes[i] != 2)
        {
            return false;
        }
    }
    return true;
}


int main()
{
    Initial();
    for (int i = 100; i < 999; i++)
    {


        for (int j = 100; j < 999; j++)
        {
            int iGewei = i % 10;
            numTimes[iGewei]++;
            int iShiwei = (i / 10) % 10;
            numTimes[iShiwei]++;
            int iBaiwei = (i / 100);
            numTimes[iBaiwei]++;

            int jGewei = j % 10;
            numTimes[jGewei]++;
            int jShiwei = (j / 10) % 10;
            numTimes[jShiwei]++;
            int jBaiwei = (j / 100);
            numTimes[jBaiwei]++;

            int num1 = i*jGewei;
            if (num1 < 1000)
            {
                int num1Gewei = num1 % 10;
                numTimes[num1Gewei]++;
                int num1Shiwei = (num1 / 10) % 10;
                numTimes[num1Shiwei]++;
                int num1Baiwei = (num1 / 100);
                numTimes[num1Baiwei]++;
            }
            else
            {
                Initial();
                continue;
            }

            int num2 = i*jShiwei;
            if (num2 < 1000)
            {
                int num2Gewei = num2 % 10;
                numTimes[num2Gewei]++;
                int num2Shiwei = (num2 / 10) % 10;
                numTimes[num2Shiwei]++;
                int num2Baiwei = (num2 / 100);
                numTimes[num2Baiwei]++;
            }
            else
            {
                Initial();
                continue;
            }

            int num3 = i*jBaiwei;
            if (num3 < 1000)
            {
                int num3Gewei = num3 % 10;
                numTimes[num3Gewei]++;
                int num3Shiwei = (num3 / 10) % 10;
                numTimes[num3Shiwei]++;
                int num3Baiwei = (num3 / 100);
                numTimes[num3Baiwei]++;
            }
            else
            {
                Initial();
                continue;
            }

            int res = i*j;
            int resGewei = res % 10;
            numTimes[resGewei]++;
            int resShiwei = (res / 10) % 10;
            numTimes[resShiwei]++;
            int resBaiwei = (res / 100) % 10;
            numTimes[resBaiwei]++;
            int resQianwei = (res / 1000) % 10;
            numTimes[resQianwei]++;
            int resWanwei = (res / 10000) % 10;
            numTimes[resWanwei]++;

            if (check())
            {
                cout << res<<endl;
                system("pause");
                return 0;
            }
            else
            {
                Initial();
                continue;
            }

        }
    }
    cout << "Nothing" << endl;
    system("pause");
    return 0;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值