生活随笔
收集整理的這篇文章主要介紹了
【PAT乙级】1031 查验身份证 (15 分)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目地址
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>using namespace std
;string str
[1005];
bool a
[1005];
int b
[17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char c
[17]={'1','0','X','9','8','7','6','5','4','3','2'};
int ans
=0;int main(void)
{int t
; cin
>>t
;for(int i
=0;i
<t
;i
++){cin
>>str
[i
];int sum
=0;for(int j
=0;j
<17;j
++){if(str
[i
][j
]>'9'||str
[i
][j
]<'0') {a
[i
]=true;break;}else{sum
+=(str
[i
][j
]-'0')*b
[j
];}}if(!a
[i
]&&c
[sum
%11]!=str
[i
][17]) a
[i
]=true;if(a
[i
]) ans
++;}if(!ans
) cout
<<"All passed";else{for(int i
=0;i
<t
;i
++){if(a
[i
]) cout
<<str
[i
]<<endl
;}}return 0;
}
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
using namespace std
;
int a
[18]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
map
<int,char>mp
;
int main(void)
{mp
[0]='1',mp
[1]='0',mp
[2]='X',mp
[3]='9',mp
[4]='8',mp
[5]='7';mp
[6]='6',mp
[7]='5',mp
[8]='4',mp
[9]='3',mp
[10]='2';int n
; cin
>>n
;bool flag
=false;for(int j
=0;j
<n
;j
++) {string s
; cin
>>s
;int sum
,i
;sum
=0;for(i
=0;i
<=16;i
++){if(s
[i
]>='0'&&s
[i
]<='9') {sum
+=(s
[i
]-'0')*a
[i
];}else {flag
=true;cout
<<s
<<endl
;break;}} if(i
==17) if(mp
[sum
%11]!=s
[17]) cout
<<s
<<endl
,flag
=true; }if(!flag
) cout
<<"All passed";return 0;
}
#include<cstdio>
#include<iostream>
#include<string>
using namespace std
;
int a
[18]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char b
[18]={'1','0','X','9','8','7','6','5','4','3','2'};
bool flag
;
int main(void)
{int n
; cin
>>n
;for(int i
=0;i
<n
;i
++){string s
; cin
>>s
;int sum
,j
;sum
=0;for(j
=0;j
<=16;j
++){if(s
[j
]>='0'&&s
[j
]<='9'){sum
+=(s
[j
]-'0')*a
[j
];}else{flag
=true;cout
<<s
<<endl
;break;}}if(j
==17&&b
[sum
%11]!=s
[17]) flag
=true,cout
<<s
<<endl
;}if(!flag
) cout
<<"All passed";return 0;
}
#include<bits/stdc++.h>
using namespace std
;
vector
<string
>ans
;
int a
[20]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char b
[20]={'1','0','X','9','8','7','6','5','4','3','2'};
int main(void)
{int n
; cin
>>n
;while(n
--){string s
; cin
>>s
;bool flag
=true;int sum
=0;for(int i
=0;i
<s
.size()-1;i
++){if(s
[i
]<'0'||s
[i
]>'9'){flag
=false;break;}sum
=(sum
+(s
[i
]-'0')*a
[i
])%11;}if(!flag
) ans
.push_back(s
);else{if(b
[sum
]!=s
[17]) ans
.push_back(s
);}}if(ans
.size()==0){cout
<<"All passed";return 0;}for(int i
=0;i
<ans
.size();i
++) cout
<<ans
[i
]<<endl
;return 0;
}
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
總結
以上是生活随笔為你收集整理的【PAT乙级】1031 查验身份证 (15 分)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。