#25502: 有比較好的方法嗎?


studyfromzhang0809@gmail.com (JHE JIA ZHANG)

School : Queensland University of Technology
ID : 135733
IP address : [111.249.11.93]
Last Login :
2021-06-24 11:17:46
a020. 身分證檢驗 | From: [114.25.42.231] | Post Date : 2021-05-27 11:45

#include <stdio.h>

#include <stdlib.h>

int main(int argc, const char * argv[]) {

    char array[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L',

        'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'X', 'Y', 'W', 'Z', 'I', 'O'}; 

    int Follow_up_code, Final_Number;

    int i = 0;

    char First_letter;

    char IDNUMBER[11];

    fgets(IDNUMBER,sizeof(IDNUMBER),stdin);

        Final_Number = 0;

        First_letter = IDNUMBER[0];

        IDNUMBER[0] = '0';

        Follow_up_code = atoi(IDNUMBER);

        for(i = 0;i < 26;i ++)

            if(array[i] == First_letter)

            {

                Final_Number = i + 10;

                break;

            }

        Final_Number = Final_Number % 10 * 9 + Final_Number / 10;

        Final_Number = Final_Number + Follow_up_code % 10;

        Follow_up_code /= 10;

        for(i = 1;i < 9;i ++)

        {

            Final_Number = Final_Number + Follow_up_code % 10 * i;

            Follow_up_code = Follow_up_code / 10;

        }

        if(Final_Number % 10 == 0)

            printf("real\n");

        else

            printf("fake\n");

    return 0;

}

 
ZeroJudge Forum