#11785: solution in C++


40171212H (Marc Polla)

學校 : 國立臺灣師範大學
編號 : 53139
來源 : [118.167.203.168]
最後登入時間 :
2023-01-28 13:16:33
a020. 身分證檢驗 | From: [1.162.75.85] | 發表日期 : 2017-03-02 23:10

#include <iostream>
#include <string>
using namespace std;

int main()
{
string ss;
while(cin>>ss)
{
int index = ss[0] - 55;
switch(index)
{
case 18:
index = 34;
break;
case 24:
index = 35;
break;
case 33:
index = 30;
break;
case 34:
index = 31;
break;
case 35:
index = 33;
break;
}
if(index > 18 && index < 24)
{
index-=1;
}
else if(index >= 23 && index <= 33)
{
if(index != 32)
{
index -= 2;
}
}
if(ss[0]=='X')
{
index = 30;
}
else if(ss[0]=='Y')
{
index = 31;
}
else if(ss[0]=='Z')
{
index = 33;
}
int temp = index % 10;
temp *= 9;
index /= 10;
index += temp;
for(int i=1;i<ss.length()-1;i++)
{
ss[i] -= 48;
ss[i] *= (9-i);
index += ss[i];
}
index += (ss[ss.length()-1]-48);
if(index%10==0)
{
std::cout<<"real"<<std::endl;
}
else{
std::cout<<"fake"<<std::endl;
}
//cout<<index<<endl;
}
return 0;
}

 
ZeroJudge Forum