1 条题解

  • 0
    @ 2025-9-17 22:02:35

    核心逻辑

    判断输入字符的类型:

    • 大写字母(A-Z)→ 输出 "upper"
    • 小写字母(a-z)→ 输出 "lower"
    • 数字字符(0-9)→ 输出 "digit"
    • 其他字符 → 输出 "other"

    代码实现

    C

    #include <stdio.h>
    
    int main() {
        char c;
        scanf("%c", &c);
        
        if (c >= 'A' && c <= 'Z') {
            printf("upper\n");
        } else if (c >= 'a' && c <= 'z') {
            printf("lower\n");
        } else if (c >= '0' && c <= '9') {
            printf("digit\n");
        } else {
            printf("other\n");
        }
        
        return 0;
    }
    

    C++

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        char c;
        cin >> c;
        
        if (c >= 'A' && c <= 'Z') {
            cout << "upper" << endl;
        } else if (c >= 'a' && c <= 'z') {
            cout << "lower" << endl;
        } else if (c >= '0' && c <= '9') {
            cout << "digit" << endl;
        } else {
            cout << "other" << endl;
        }
        
        return 0;
    }
    

    Python

    c = input().strip()  # 读取输入的单个字符
    if c.isupper():
        print("upper")
    elif c.islower():
        print("lower")
    elif c.isdigit():
        print("digit")
    else:
        print("other")
    

    信息

    ID
    29
    时间
    1000ms
    内存
    64MiB
    难度
    9
    标签
    递交数
    7
    已通过
    6
    上传者