判断车牌号问题,英文+五位数字和大写字母组成的编码组成,比如6666A,6666B,
样例1
输入 6666A
输出yes
样例2
输入6666!
输出no
#include
using namespace std;
int main()
{
int a
cin>>a;
}
你这题目描述有问题吧,五位数字写错了吧,感觉应该是车牌号长度是5位(数字+大写字母共5位)。否则6666A这个只有4个数字,不可能输出yes。
运行结果及代码如下:
代码:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
cin >> str; //输入车牌号
if(str.length() != 5)
{
cout << "no";
return 0;
}else
{
int i=0;
while(i<str.length())
{
if( (str.at(i)>='0' && str.at(i)<='9') || (str.at(i)>='A' && str.at(i)<='Z') )
i++;
else
{
cout << "no";
return 0;
}
}
cout <<"yes";
return 0;
}
}
供参考:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
int i=0,cn=0,dn=0;
char s[8];
scanf("%s",s);
while(s[i])
{
if(isdigit(s[i])) dn++;
else if(isupper(s[i]))cn++;
i++;
}
if((dn+cn)==5 && i == 5)
printf("yes");
else
printf("no");
return 0;
}