B Quality of Check Digits

原题戳这里



由4位数加前导0求出第5位数,这5位数根据表格给的推回去是0,求给出的表格有多少个数抄错检查不出来


暴力跑表格a了...2333333

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <algorithm>

using namespace std;

int s[20][20];

int judge(int a1, int a2, int a3, int a4, int x)
{
    int b1, b2, b3, b4, b5;
    int y;
    int a, aa;
    a = a1 * 10000 + a2 * 1000 + a3 * 100 + 10 * a4 + x;
    for(b1 = 0; b1 <= 9; b1++)
    {
        b2 = a2;
        b3 = a3;
        b4 = a4;
        b5 = x;
        aa = b1 * 10000 + b2 * 1000 + b3 * 100 + 10 * b4 + b5;
        if(a != aa)
        {
            y = s[0][b1];
            y = s[y][b2];
            y = s[y][b3];
            y = s[y][b4];
            y = s[y][b5];
            if(y == 0)
            {
                return 1;
            }
        }
    }
    for(b2 = 0; b2 <= 9; b2++)
    {
        b1 = a1;
        b3 = a3;
        b4 = a4;
        b5 = x;
        aa = b1 * 10000 + b2 * 1000 + b3 * 100 + 10 * b4 + b5;
        if(a != aa)
        {
            y = s[0][b1];
            y = s[y][b2];
            y = s[y][b3];
            y = s[y][b4];
            y = s[y][b5];
            if(y == 0)
            {
                return 1;
            }
        }
    }
    for(b3 = 0; b3 <= 9; b3++)
    {
        b1 = a1;
        b2 = a2;
        b4 = a4;
        b5 = x;
        aa = b1 * 10000 + b2 * 1000 + b3 * 100 + 10 * b4 + b5;
        if(a != aa)
        {
            y = s[0][b1];
            y = s[y][b2];
            y = s[y][b3];
            y = s[y][b4];
            y = s[y][b5];
            if(y == 0)
            {
                return 1;
            }
        }
    }
    for(b4 = 0; b4 <= 9; b4++)
    {
        b1 = a1;
        b2 = a2;
        b3 = a3;
        b5 = x;
        aa = b1 * 10000 + b2 * 1000 + b3 * 100 + 10 * b4 + b5;
        if(a != aa)
        {
            y = s[0][b1];
            y = s[y][b2];
            y = s[y][b3];
            y = s[y][b4];
            y = s[y][b5];
            if(y == 0)
            {
                return 1;
            }
        }
    }
    for(b5 = 0;b5 <= 9;b5++)
    {
    	b1 = a1;
        b2 = a2;
        b3 = a3;
        b4 = a4;
        aa = b1 * 10000 + b2 * 1000 + b3 * 100 + 10 * b4 + b5;
        if(a != aa)
        {
            y = s[0][b1];
            y = s[y][b2];
            y = s[y][b3];
            y = s[y][b4];
            y = s[y][b5];
            if(y == 0)
            {
                return 1;
            }
        }
    }
    b1 = a1;
    b2 = a2;
    b3 = a3;
    b4 = a4;
    b5 = x;
    swap(b1,b2);
    aa = b1 * 10000 + b2 * 1000 + b3 * 100 + 10 * b4 + b5;
    if(aa != a)
    {
        y = s[0][b1];
        y = s[y][b2];
        y = s[y][b3];
        y = s[y][b4];
        y = s[y][b5];
        if(y == 0)
        {
            return 1;
        }
    }
    b1 = a1;
    b2 = a2;
    b3 = a3;
    b4 = a4;
    b5 = x;
    swap(b2,b3);
    aa = b1 * 10000 + b2 * 1000 + b3 * 100 + 10 * b4 + b5;
    if(aa != a)
    {
        y = s[0][b1];
        y = s[y][b2];
        y = s[y][b3];
        y = s[y][b4];
        y = s[y][b5];
        if(y == 0)
        {
            return 1;
        }
    }
    b1 = a1;
    b2 = a2;
    b3 = a3;
    b4 = a4;
    b5 = x;
    swap(b3,b4);
    aa = b1 * 10000 + b2 * 1000 + b3 * 100 + 10 * b4 + b5;
    if(aa != a)
    {
        y = s[0][b1];
        y = s[y][b2];
        y = s[y][b3];
        y = s[y][b4];
        y = s[y][b5];
        if(y == 0)
        {
            return 1;
        }
    }
    b1 = a1;
    b2 = a2;
    b3 = a3;
    b4 = a4;
    b5 = x;
    swap(b4,b5);
    aa = b1 * 10000 + b2 * 1000 + b3 * 100 + 10 * b4 + b5;
    if(aa != a)
    {
        y = s[0][b1];
        y = s[y][b2];
        y = s[y][b3];
        y = s[y][b4];
        y = s[y][b5];
        if(y == 0)
        {
            return 1;
        }
    }
    return 0;
}

int main()
{
    int a1, a2, a3, a4, sum;
    int i, j, x;
    sum = 0;
    for(i = 0; i < 10; i++)
    {
        for(j = 0; j < 10; j++)
        {
            cin>>s[i][j];
        }
    }
    for(a1 = 0; a1 < 10; a1++)
    {
        for(a2 = 0; a2 < 10; a2++)
        {
            for(a3 = 0; a3 < 10; a3++)
            {
                for(a4 = 0; a4 < 10; a4++)
                {
                    x = s[0][a1];
                    x = s[x][a2];
                    x = s[x][a3];
                    x = s[x][a4];
                    if(judge(a1,a2,a3,a4,x))
                    {
                        sum++;
                    }
                }
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值