PAT-1031.查验身份证(15)

来源:互联网 发布:淘宝怎么上第三方活动 编辑:程序博客网 时间:2024/06/05 19:14
#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;

}

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

对输入的字符串的前十七位进行查验,如果不为数字则输出该字符串。如果全为数字,然后再对校检位进行比对。