• B1031


    这里写图片描述这里写图片描述这里写图片描述

    #include <stdio.h>
    #include <string.h>
    // B1031
    // 权重 w[0] = 7, w[1] = 9
    int w[20] = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
    // 校验码, chaneg[0] = '1', change[1] = '0',...
    char change[15] = {'1','0','X','9','8','7', '6','5','4','3','2'};
    
    int main(){
        int n;
        scanf("%d", &n);
        bool flag = true;
        char str[20];
    
        for (int i=0; i<n; i++){
            scanf("%s", str);
            int j,last = 0;
            for (j = 0; j<17; j++){
                if (!(str[j]>='0' && str[j]<='9')) break;
                last = last + (str[j]-'0')*w[j];
            }
    
            if (j < 17){
                flag = false;
                printf("%s", str);
            }else{
                if (change[last%11] != str[17]){
                    flag = false;
                    printf("%s", str);
                }
            }
        }
        if (flag == true){
            printf("All passed
    ");
        }
        return 0;
    }
  • 相关阅读:
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    codevs 1501 二叉树最大宽度和高度x
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12538174.html
Copyright © 2020-2023  润新知