3123:【例21.3】 字符类型判断
[例 21.3] 字符类型判断
C语言源码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char a;
scanf("%c",&a);
if('A'<=a&&a<='Z') printf("upper");
else if('a'<=a&&a<='z') printf("lower");
else if('0'<=a&&a<='9') printf("digit");
else printf("other");
return 0;
}
C++代码:
#include <bits/stdc++.h>
using namespace std;
long long n;
char c;
int main(){
cin >> c;
if(c >= 'A' and c <= 'Z')//是否大写字符
cout << "upper";
else if(c >= '0' and c <= '9')//是否数字
cout << "digit";
else if(c >= 'a' and c <= 'z')//是否小写字符
cout << "lower";
else//是否其它字符
cout << "other";
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
char ch;
cin>>ch;
if( ch>='a' && ch<='z' )
{
cout<<"lower"<<endl;
}
else
{
if( ch>='A' && ch<='Z' )
{
cout<<"upper"<<endl;
}
else
{
if( ch>='0' && ch<='9' )
{
cout<<"digit"<<endl;
}
else
{
cout<<"other"<<endl;
}
}
}
return 0;
}
python3代码:
a=input()
if 'A'<=a and a<='Z':
print("upper")
elif 'a'<=a and a<='z':
print("lower")
elif '0'<=a and a<='9':
print("digit")
else :
print("other")
3065:练12.4计算并联电阻的阻值(Scratch、C、C++、python)
3066:【例13.1】空格分隔输出(C、C++)
3067:【例13.2】 电子表(Scratch、C、C++、python)
3068:【例13.3】时间差(C、C++、python)