Written by Master

大师  •  8天前


include <bits/stdc++.h>

using namespace std; // #define _debug 0

int main() {

int n;
cin >> n;
string ss[n];
for (int i = 0; i < n; i++)
{
    cin >> ss[i];
}

for (int i = 0; i < n; i++)
{
    int m_day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    bool pass = true;
    string s, ts;
    s = ss[i];

    // 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2

    int weights[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
    int sum = 0;
    for (int j = 0; j < 17; j++)
    {
        sum += (s[j] - '0') * weights[j];
    }

    // cout << sum % 11;

    // 余数只可能有0 1 2 3 4 5 6 7 8 9 10这11个数字。其分别对应的最后一位身份证的号码为1 0 X 9 8 7 6 5 4 3 2

    char lastnum;
    // cout << sum % 11;
    switch (sum % 11)
    {
    case 0:
        lastnum = '1';
        break;
    case 1:
        lastnum = '0';
        break;
    case 2:
        lastnum = 'X';
        break;
    case 3:
        lastnum = '9';
        break;
    case 4:
        lastnum = '8';
        break;
    case 5:
        lastnum = '7';
        break;
    case 6:
        lastnum = '6';
        break;
    case 7:
        lastnum = '5';
        break;
    case 8:
        lastnum = '4';
        break;
    case 9:
        lastnum = '3';
        break;
    case 10:
        lastnum = '2';
        break;
    }
    // cout << lastnum;
    int year = stoi(s.substr(6, 4));
    int month = stoi(s.substr(10, 2));
    int day = stoi(s.substr(12, 2));
    if (year < 1980 || year > 2006)
    {
        pass = false;
        cout << 'Y' << endl;
    }
    else
    {
        if (year % 4 == 0)
            m_day[2] = 29;
        if (month < 1 || month > 12)
        {
            pass = false;
            cout << 'M' << endl;
        }
        else
        {
            if (day > m_day[month])
            {
                pass = false;
                cout << 'D' << endl;
            }
            else
            {
                if (lastnum != s.back())
                {
                    pass = false;
                    s.back() = lastnum;
                    cout << s << endl;
                }
            }
        }
    }
    if (pass)
    {
        cout << 'T' << endl;
    }
}

ifdef _debug

cout << endl;
system("pause");

endif

return 0;

}


评论:

请先登录,才能进行评论