将字符串中的小写字母转换成大写字母

GitHub跳转原题关系图返回列表

调用字符串 upper 将所有小写字母统一转换为大写字母。

OJ: noi_openjudge

题目 ID: ch0107-13

难度:入门

标签:字符串python

日期: 2026-07-30 23:01

题意

将一行字符串中的所有小写字母转换为大写,其他字符不变。

思路

upper() 返回转换后的新字符串,直接符合题意。

代码

Python代码

python
print(input().upper())

C++代码

cpp
#include <cstdio>
#include <cstring>

char str[500];
int idx=0;
int main(){
    char t;
    while(1){
        int ret = scanf("%c",&t);
        if( t == '\n' || t == '\r' || ret == EOF)
            break;
        str[++idx] = t;
    }
    int i;
    for (i=1;i<=idx;i++){
        if( str[i] >='a' &&  str[i] >='a' ){
            printf("%c",str[i]+'A'-'a');
        }
        else
            printf("%c",str[i]);
    }
    return 0;
}

复杂度

时间复杂度和输出空间均为 O(n)O(n)

总结

统一大小写优先使用字符串内置方法。