a020.
身分證檢驗
| From: [1.170.22.242] |
發表日期
:
2014-11-07 22:07
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char input[11];
int sum = 0, i, j;
while (scanf("%s", input) != EOF){
sum = 0;
printf("%d\n", input[0]);
if (input[0] >= 'A' && input[0] <= 'H')
input[0] -= 'A' - 10;
else if (input[0] <= 'N'){
if (input[0] == 'I')
input[0] = 34;
else input[0] -= 'J' - 18;
}
else if (input[0] <= 'V'){
if (input[0] == 'O')
input[0] = 35;
else input[0] -= 'V' - 29;
}
else if (input[0] <= 'Z'){
if (input[0] == 'W')
input[0] = 32;
else input[0] -= 'Z' - 33;
} /*首字母數字轉換完畢*/
sum += input[0] / 10 + input[0] % 10 * 9;
for (i=1, j=8; i<=8; i++, j--){
input[i] -= '0';
sum += input[i] * j;
}
for (i=0; i<10; i++)
printf("%d ", input[i]);
sum += (input[9] -= '0');
printf("\nsum = %d\n", sum);
if ((sum%10) == 0)
printf("real\n");
else printf("fake\n");
}
system("pause");
return 0;
}
第 1 測資點(0%): WA (line:10) 答案不正確您的答案為: fake 正確答案為: real
一開始沒注意到W變成32,改了之後還是跑出WA……
麻煩各位大大解惑了