程式碼連結: http://ideone.com/pxSeu6
有將其他人給的測資丟進去測試 但抓不出為何會fake
#include <stdio.h>
char c[20];
int num[15];
int j,k;
int numindex;
int sum;
int main(void) {
while(gets(c)!=NULL){
numindex = 1;
sum = 0;
for(j=0;c[j]!='\0';j++){
if(c[j]>=65){
switch(c[j]){
case 'A':
num[0]=10;
break;
case 'B':
num[0]=11;
break;
case 'C':
num[0]=12;
break;
case 'D':
num[0]=13;
break;
case 'E':
num[0]=14;
break;
case 'F':
num[0]=15;
break;
case 'G':
num[0]=16;
break;
case 'H':
num[0]=17;
break;
case 'I':
num[0]=34;
break;
case 'j':
num[0]=18;
break;
case 'K':
num[0]=19;
break;
case 'L':
num[0]=20;
break;
case 'M':
num[0]=21;
break;
case 'N':
num[0]=22;
break;
case 'O':
num[0]=35;
break;
case 'p':
num[0]=23;
break;
case 'Q':
num[0]=24;
break;
case 'R':
num[0]=25;
break;
case 'S':
num[0]=26;
break;
case 'T':
num[0]=27;
break;
case 'U':
num[0]=28;
break;
case 'V':
num[0]=29;
break;
case 'W':
num[0]=32;
break;
case 'X':
num[0]=30;
break;
case 'Y':
num[0]=31;
break;
case 'Z':
num[0]=33;
break;
}
}
else{
num[j]=c[j]-48;
}
}
for(k=8;k>0 ;k--){
sum= sum + num[numindex]*k;
numindex ++;
}
sum = num[9]+sum;
sum = sum + (num[0]/10) + (num[0]%10)*9 ;
if(sum%10==0){
printf("real\n");
}
else{
printf("fake\n");
}
}
return 0;
}