#25671: 初學者寫法請見諒,用更好寫法歡迎告訴我


jiananlin031@gmail.com (小迪芯)

School : 修平科技大學
ID : 156261
IP address : [125.227.79.111]
Last Login :
2021-06-11 07:30:54
a020. 身分證檢驗 | From: [114.41.197.250] | Post Date : 2021-06-11 07:11

#include <iostream>

#include <cstdlib>

using namespace std;

int main(int argc, char** argv) {

  string card,one,s1,s2,s3,s4,s5,s6,s7,s8,s9;

  int s0,sum,sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8,sum9;

  cin >> card;

  one = card[0];

  s1 = card[1]; s2 = card[2]; s3 = card[3]; s4 = card[4]; s5 = card[5]; s6 = card[6]; s7 = card[7]; s8 = card[8]; s9 = card[9];

  sum1 = atoi(s1.c_str()); sum2 = atoi(s2.c_str());sum3 = atoi(s3.c_str());sum4 = atoi(s4.c_str());sum5 = atoi(s5.c_str());sum6 = atoi(s6.c_str());sum7 = atoi(s7.c_str());sum8 = atoi(s8.c_str());sum9 = atoi(s9.c_str());

  sum = sum1 * 8 + sum2 * 7 + sum3 * 6 + sum4 * 5 + sum5 * 4 + sum6 * 3 + sum7 * 2 + sum8 * 1 + sum9;

  if(one == "A"){s0 = (0*9)+1;}

  else if (one == "B"){s0 = (1*9)+1;}

  else if (one == "C"){s0 = (2*9)+1;}

  else if (one == "D"){s0 = (3*9)+1;}

  else if (one == "E"){s0 = (4*9)+1;}

  else if (one == "F"){s0 = (5*9)+1;}

  else if (one == "G"){s0 = (6*9)+1;}

  else if (one == "H"){s0 = (7*9)+1;}

  else if (one == "I"){s0 = (4*9)+3;}

  else if (one == "J"){s0 = (8*9)+1;}

  else if (one == "K"){s0 = (9*9)+1;}

  else if (one == "L"){s0 = (0*9)+2;}

  else if (one == "M"){s0 = (1*9)+2;}

  else if (one == "N"){s0 = (2*9)+2;}

  else if (one == "O"){s0 = (5*9)+3;}

  else if (one == "P"){s0 = (3*9)+2;}

  else if (one == "Q"){s0 = (4*9)+2;}

  else if (one == "R"){s0 = (5*9)+2;}

  else if (one == "S"){s0 = (6*9)+2;}

  else if (one == "T"){s0 = (7*9)+2;}

  else if (one == "U"){s0 = (8*9)+2;}

  else if (one == "V"){s0 = (9*9)+2;}

  else if (one == "W"){s0 = (2*9)+3;}

  else if (one == "X"){s0 = (0*9)+3;}

  else if (one == "Y"){s0 = (1*9)+3;}

  else if (one == "Z"){s0 = (3*9)+3;}

  s0 = s0 / 1 % 10;

  sum = sum / 1 % 10;

  sum = sum + s0;

  if(sum % 10 == 0){

  cout << "real\n";

  }

 else{

  cout << "fake\n";

  }

}

 
#25898: Re:初學者寫法請見諒,用更好寫法歡迎告訴我


candy13222 (茶)

School : 國立暨南國際大學
ID : 73925
IP address : [163.22.18.49]
Last Login :
2022-01-11 13:15:39
a020. 身分證檢驗 | From: [118.170.216.133] | Post Date : 2021-07-02 20:53

我是用MAP的方法

 
#25917: Re:初學者寫法請見諒,用更好寫法歡迎告訴我


nppstcc1001050311@gmail.com (索伯)

School : No School
ID : 136521
IP address : [60.248.175.252]
Last Login :
2022-01-04 04:08:33
a020. 身分證檢驗 | From: [123.194.41.143] | Post Date : 2021-07-04 16:39

可以先開一個陣列用來存字母對數字的表 int y[] = {10, 11, 12, 13, 14, 15, 16, 17, 34, 18, 19, 20, 21, 22, 35, 23, 24, 25, 26, 27, 28, 29, 32, 30, 31, 33}; 再依字母取值 int k = letterpow[x[0] - 'A'];  
#25918: Re:初學者寫法請見諒,用更好寫法歡迎告訴我


nppstcc1001050311@gmail.com (索伯)

School : No School
ID : 136521
IP address : [60.248.175.252]
Last Login :
2022-01-04 04:08:33
a020. 身分證檢驗 | From: [123.194.41.143] | Post Date : 2021-07-04 16:42

可以先開一個陣列用來存字母對數字的表 int y[] = {10, 11, 12, 13, 14, 15, 16, 17, 34, 18, 19, 20, 21, 22, 35, 23, 24, 25, 26, 27, 28, 29, 32, 30, 31, 33};
再依字母取值 int k = y[x[0] - 'A'];



 
ZeroJudge Forum