L1-016 查验身份证
题目 L1-016 查验身份证
思路分析
isalpha/isdigit 字母/数字
char c;
//判断是否为字母:
//可以这样:
if(c>='a' && c<='z' || c>='A' && c<='Z')
//也可用库函数:
//检查一个字符是否是字母(a-z 或 A-Z)是 返回非零值,不是 返回零
if(isalpha(ch1))
//判断是否为数字:
//可以这样:
if(c>='0' && c<='9')
//也可用库函数:
//检查一个字符是否是十进制数字(0-9),是 返回非零值,不是 返回零
if(isdigit(int ch))
代码实现
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long LL;
const int N=20;
int q[N]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char hs[N]={'1','0','X','9','8','7','6','5','4','3','2'};
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
// for(int i=0;i<17;i++) cout<<q[i]<<" ";
int n;cin>>n;
bool havefalse=false;
while(n--){
string s;cin>>s;
LL total=0;
char jym=s.back();
bool isValid = true;
for(int i=0;i<17;i++){
// if(isalpha(s[i])){
if(!isdigit(s[i])) {
cout<<s<<endl;
havefalse=true;
isValid = false;
break;
}
total += (s[i] - '0') * q[i];
}
// cout<<"total: "<<total<<endl;
if(isValid){
int Z = total%11;
if(hs[Z]!=jym){
cout<<s<<endl;
havefalse=true;
}
}
}
if(!havefalse) cout<<"All passed"<<endl;
return 0;
}
同类题型
视频讲解
⬅️ L1-015 跟奥巴马一起画方块 🏠 00-天梯赛 ➡️ L1-017 到底有多二
💬 评论