您的位置:首页 > 其它

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;
}

/************************************************************/

对输入的字符串的前十七位进行查验,如果不为数字则输出该字符串。如果全为数字,然后再对校检位进行比对。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: