a020
輸入說明 :
一組身分證號碼
輸出說明 :
輸出 real or fake
先看開頭是什麼字母,看它是什麼對照題目換到另一個整數陣列的第一格和第二格(所以整數陣列要宣告有11格)(字元陣列也要11格才不會錯),接著把字元轉成數字,再來就去對整數陣列做題目說的運算,最後%10,輸出
#include<stdio.h>
#include<string.h>
int main(){
char identity[11];
int check[11];
int i;
int sum,temp;
while(scanf("%s",&identity)!=EOF)
{
if(identity[0]=='A')
{
check[0]=1;
check[1]=0;
}
if(identity[0]=='B')
{
check[0]=1;
check[1]=1;
}
if(identity[0]=='C')
{
check[0]=1;
check[1]=2;
}
if(identity[0]=='D')
{
check[0]=1;
check[1]=3;
}
if(identity[0]=='E')
{
check[0]=1;
check[1]=4;
}
if(identity[0]=='F')
{
check[0]=1;
check[1]=5;
}
if(identity[0]=='G')
{
check[0]=1;
check[1]=6;
}
if(identity[0]=='H')
{
check[0]=1;
check[1]=7;
}
if(identity[0]=='I')
{
check[0]=3;
check[1]=4;
}
if(identity[0]=='J')
{
check[0]=1;
check[1]=8;
}
if(identity[0]=='K')
{
check[0]=1;
check[1]=9;
}
if(identity[0]=='L')
{
check[0]=2;
check[1]=0;
}
if(identity[0]=='M')
{
check[0]=2;
check[1]=1;
}
if(identity[0]=='N')
{
check[0]=2;
check[1]=2;
}
if(identity[0]=='O')
{
check[0]=3;
check[1]=5;
}
if(identity[0]=='P')
{
check[0]=2;
check[1]=3;
}
if(identity[0]=='Q')
{
check[0]=2;
check[1]=4;
}
if(identity[0]=='R')
{
check[0]=2;
check[1]=5;
}
if(identity[0]=='S')
{
check[0]=2;
check[1]=6;
}
if(identity[0]=='T')
{
check[0]=2;
check[1]=7;
}
if(identity[0]=='U')
{
check[0]=2;
check[1]=8;
}
if(identity[0]=='V')
{
check[0]=2;
check[1]=9;
}
if(identity[0]=='W')
{
check[0]=3;
check[1]=2;
}
if(identity[0]=='X')
{
check[0]=3;
check[1]=0;
}
if(identity[0]=='Y')
{
check[0]=3;
check[1]=1;
}
if(identity[0]=='Z')
{
check[0]=3;
check[1]=3;
}
for(i=1;i<10;i++)
{
if(identity[i]=='0')
check[i+1]=0;
if(identity[i]=='1')
check[i+1]=1;
if(identity[i]=='2')
check[i+1]=2;
if(identity[i]=='3')
check[i+1]=3;
if(identity[i]=='4')
check[i+1]=4;
if(identity[i]=='5')
check[i+1]=5;
if(identity[i]=='6')
check[i+1]=6;
if(identity[i]=='7')
check[i+1]=7;
if(identity[i]=='8')
check[i+1]=8;
if(identity[i]=='9')
check[i+1]=9;
}
sum=0;
sum=check[0]+check[10];
for(i=1;i<10;i++)
{
temp=check[i]*(10-i);
sum+=temp;
}
if(sum%10==0)
printf("real\n");
else
printf("fake\n");
}
return 0;
}