读入一些字符串,将其中的小写字母转成大写字母(其他字符不变)。
时间: 2023-04-24 21:01:42 浏览: 54
可以使用Python语言的upper()函数将小写字母转成大写字母,具体实现代码如下:
```
# 读入字符串
s = input()
# 将小写字母转成大写字母
s = s.upper()
# 输出结果
print(s)
```
其中,input()函数用于读入字符串,upper()函数用于将字符串中的小写字母转成大写字母,print()函数用于输出结果。
相关问题
读入一些字符串,将其中的小写字母转成大写字母(其他字符不变)。c++
可以使用 `toupper()` 函数将小写字母转成大写字母,代码如下:
```c++
#include <iostream>
#include <cstring>
#include <cctype>
int main() {
const int MAXN = 100;
char str[MAXN];
std::cout << "Please enter a string: ";
std::cin.getline(str, MAXN);
for (int i = 0; i < strlen(str); i++) {
if (islower(str[i])) {
str[i] = toupper(str[i]);
}
}
std::cout << "The result is: " << str << std::endl;
return 0;
}
```
运行结果:
```
Please enter a string: Hello, world!
The result is: HELLO, WORLD!
```
对一个以#结束的字符串将其小写字母全部转换成大写字母 把大写字母全部转换成小写字母 其他字符不变输出C语言
好的,以下是 C 语言代码实现:
```c
#include <stdio.h>
#include <ctype.h> // 包含 toupper 和 tolower 函数
int main() {
char str[1000];
int i = 0;
char c = getchar(); // 逐个读入字符
while (c != '#') {
str[i++] = c; // 存入字符串中
c = getchar();
}
str[i] = '\0'; // 字符串结尾
for (int j = 0; str[j] != '\0'; j++) {
if (islower(str[j])) { // 如果是小写字母
putchar(toupper(str[j])); // 转换成大写字母输出
} else if (isupper(str[j])) { // 如果是大写字母
putchar(tolower(str[j])); // 转换成小写字母输出
} else {
putchar(str[j]); // 其他字符不变输出
}
}
return 0;
}
```
以上代码会逐个读入字符,存入字符数组中形成字符串。然后遍历字符串中的每个字符,如果是小写字母则转换成大写字母输出,如果是大写字母则转换成小写字母输出,其他字符不变输出。最后输出结果。