#21116: C++解答


ololo.catgirl@gmail.com (烏魯ö呆萌貓耳娘)

學校 : 不指定學校
編號 : 110460
來源 : [27.242.32.56]
最後登入時間 :
2020-04-13 22:20:13
a020. 身分證檢驗 | From: [27.242.32.56] | 發表日期 : 2020-04-13 20:37

#include <iostream>

#include <string>

using namespace std;

 

int main(void) {

  int data[] = { 1, 10, 19, 28, 37, 46, 55, 64, 39, 73, 82,  2, 11,

                20, 18, 29, 38, 47, 56, 65, 74, 83, 21,  3, 12, 30};

  string str;

  while(cin >> str) {

    int top, discriminant,num[9] = {0}, index = 0;

    top = data[str[0] - 65];

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

      if(i == 9) {

        num[index] = str[i] - 48;

        break;

      }

      num[index] = (str[i] - 48) * (9 - i); index++;

    }

    discriminant = top;

    for(int i = 0; i <= 8; i++)

      discriminant += num[i];

    cout << (discriminant % 10 == 0 ? "real" : "fake") << endl;

  }

  return 0;

}

 

 
ZeroJudge Forum