PAT-1031.查验身份证(15)
2017-12-09 16:11
344 查看
#include<iostream>
#include<string>
using namespace std;
int main()
{
int N,i,j=0,k=0,B[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2},Z,x;
char A[11]={'1','0','X','9','8','7','6','5','4','3','2'};
string C;
cin>>N;
cin.get();
while (j<N)
{
Z=x=0;
cin>>C;
for(i=0;i<17;++i)
{
if(C[i]<='9'&&C[i]>='0')
Z+=(C[i]-'0')*B[i];
else
{x=1;}
}
if(x==1)
{
k++;
if(k==1)
cout<<C;
else
cout<<endl<<C;
}
else
{
Z=Z%11;
if(A[Z]!=C[i])
{
k++;
if(k==1)
cout<<C;
else
cout<<endl<<C;
}
}
j++;
}
if(k==0)
cout<<"All passed";
return 0;
}
/************************************************************/
对输入的字符串的前十七位进行查验,如果不为数字则输出该字符串。如果全为数字,然后再对校检位进行比对。
#include<string>
using namespace std;
int main()
{
int N,i,j=0,k=0,B[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2},Z,x;
char A[11]={'1','0','X','9','8','7','6','5','4','3','2'};
string C;
cin>>N;
cin.get();
while (j<N)
{
Z=x=0;
cin>>C;
for(i=0;i<17;++i)
{
if(C[i]<='9'&&C[i]>='0')
Z+=(C[i]-'0')*B[i];
else
{x=1;}
}
if(x==1)
{
k++;
if(k==1)
cout<<C;
else
cout<<endl<<C;
}
else
{
Z=Z%11;
if(A[Z]!=C[i])
{
k++;
if(k==1)
cout<<C;
else
cout<<endl<<C;
}
}
j++;
}
if(k==0)
cout<<"All passed";
return 0;
}
/************************************************************/
对输入的字符串的前十七位进行查验,如果不为数字则输出该字符串。如果全为数字,然后再对校检位进行比对。
相关文章推荐
- PAT乙级1031(C语言)-查验身份证(15)
- PAT-乙级-1031. 查验身份证(15)
- 乙级 PAT 1031. 查验身份证(15)
- PAT乙级1031. 查验身份证(15)
- PAT 1031. 查验身份证(15)
- PAT乙级 1031. 查验身份证(15)
- PAT 1031. 查验身份证(15)
- 1031. 查验身份证(15) PAT 乙级
- 1031. 查验身份证(15)-PAT乙级真题
- PAT (Basic Level) Practise (中文) 1031. 查验身份证(15)
- PAT1031 查验身份证(15)
- PAT (Basic Level) Practise (中文)1031. 查验身份证(15)
- PAT 乙级 1031. 查验身份证(15) Java版
- PAT乙级 1031. 查验身份证(15)
- 1031. 查验身份证(15) PAT乙级真题
- 【pat】1031. 查验身份证(15)
- 1031. 查验身份证(15)-浙大PAT乙级真题java实现
- PAT乙级 1031. 查验身份证(15) 标志要清零!!!!!!!!!
- PAT(basic level) 1031 查验身份证(15)
- PAT Basic 1031. 查验身份证(15)(C语言实现)