patB1031 查验身份证

#include <iostream>
#include <cstring> 
using namespace std;
int weight[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
int z[11]={0,1,2,3,4,5,6,7,8,9,10};
char m[11]={'1','0','X','9','8','7','6','5','4','3','2'};


string str[101];
int calculate(string ss){
int ans=0;
for(int i=0;i<17;i++){
ans+=(ss[i]-'0')*weight[i];
}
return ans;
}
int main(int argc, char** argv) {
int n;
cin>>n;
for(int i=0;i<n;i++) cin>>str[i];
int count=0,countfalse=0;
while(1){
//calculate
int temp=calculate(str[count]);
int index=temp%11;
//compare
if(str[count][17]!=m[index]) {
cout<<str[count]<<endl;
countfalse++;
}
count++;
if(count==n) break;
}
if(countfalse==0) cout<<"All passed"<<endl;
return 0;

}



阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭