'A'..'Z'(大写)或 'a'..'z'(小写)范围内。classify(ch),若 A ≤ ch ≤ Z 输出 "up",否则输出 "low";主函数完成输入输出。O(1),只进行一次比较判断。O(1),仅常数级额外变量。# 功能函数:根据字符返回"up"或"low"
def classify(ch: str) -> str:
# 使用ASCII区间判断是否为大写字母
return "up" if 'A' <= ch <= 'Z' else "low"
def main():
# 读取一行,保证为单个字母
s = input().strip()
ch = s[0] # 取第一个字符
# 输出结果
print(classify(ch))
if __name__ == "__main__":
main()
import java.util.Scanner;
public class Main {
// 功能函数:根据字符返回"up"或"low"
static String classify(char ch) {
// 使用ASCII区间判断是否为大写字母
if ('A' <= ch && ch <= 'Z') return "up";
return "low";
}
public static void main(String[] args) {
// 题目规模很小,直接使用Scanner读取
Scanner sc = new Scanner(System.in);
String s = sc.next().trim(); // 保证输入为单个字母
char ch = s.charAt(0);
// 输出结果
System.out.println(classify(ch));
sc.close();
}
}
#include <iostream>
using namespace std;
// 功能函数:根据字符返回"up"或"low"
string classify(char ch) {
// 使用ASCII区间判断是否为大写字母
if ('A' <= ch && ch <= 'Z') return "up";
return "low";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
char ch;
// 读取单个字符
cin >> ch;
// 输出结果
cout << classify(ch) << '\n';
return 0;
}
给你一个字母,你需要判断这个字母是大写还是小写,如果是大写,输出“up“,否则,输出“low"。
输入一行,一个单独的字符,保证是大写字母或者小写字母
如果是大写字母,输出"up",如果是小写字母,输出"low "
输入
A
输出
up
输入
a
输出
low