# 設定英文字母對應的數字 letter_to_digit = { 'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15, 'G': 16, 'H': 17, 'I': 34, 'J': 18, 'K': 19, 'L': 20, 'M': 21, 'N': 22, 'O': 35, 'P': 23, 'Q': 24, 'R': 25, 'S': 26, 'T': 27, 'U': 28, 'V': 29, 'W': 32, 'X': 30, 'Y': 31, 'Z': 33 } def validate_id(id_number): # 將英文字母轉換成對應的數字 first_digit = letter_to_digit[id_number[0]] # 計算個位數乘9再加上十位數的數字 first_two_digits = first_digit // 10 + (first_digit % 10) * 9 total = first_two_digits # 計算各數字從右到左依次乘1、2、3、4....8 for i in range(1, len(id_number) - 1): total += int(id_number[i]) * (9 - i) # 求出(2),(3) 及最後一碼的和 total += int(id_number[-1]) # 判斷是否為 real if total % 10 == 0: return "real" else: return "fake" # 讀取輸入並處理 input_lines = [] try: while True: line = input() input_lines.append(line) except EOFError: pass # 計算並輸出判斷結果 for line in input_lines: result = validate_id(line) print(result) Close
PYTHON
|