1031

作者: 峡迩 | 来源:发表于2017-08-21 16:39 被阅读0次
    
    #include "stdafx.h"
    
    #include<iostream>
    #include<vector>
    #include<algorithm>
    #include<cctype>
    #include<string>
    
    using namespace std;
    
    bool check(string id)
    {
        const vector<int> weight = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 };//权值,加权平均!
        const vector<char> check_code = { '1','0','X','9','8','7','6','5','4','3','2' };
    
        int sum = 0;
        for (size_t i = 0; i < 17; ++i)
        {
            if (!isdigit(id[i]))
                return false;
            string tmp(1, id[i]);
            int tmp_num = stoi(tmp);
            sum = sum + tmp_num*weight[i];
        }
        int z = sum % 11;
        if (id[17] == check_code[z])
            return true;
        else
            return false;
    
    }
    
    int main()
    {
        vector<string> input_info;
        unsigned n;
        cin >> n;
        string tmp;
        for (unsigned i = 0; i < n; ++i)
        {
            cin >> tmp;
            if (!check(tmp))
                input_info.push_back(tmp);
        }
    
        if (n == input_info.size())
            cout << "All passed";
        else
        {
            for (size_t i = 0; i < input_info.size(); ++i)
            {
                if (i == (input_info.size() - 1))
                    cout << input_info[i];
                else
                    cout << input_info[i] << endl;
            }
        }
    
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:1031

          本文链接:https://www.haomeiwen.com/subject/lrqhdxtx.html