3.1蓝桥杯每日一个知识点,大小写转化
islower/isupper函数
- C++中的字符分类函数,用于检查一个字符的大小写
- 需要包含头文件
<cctype>或者万能头文件<bit/stdc++.h> - 函数返回值1为bool类型
if(islower(ch1)){
cout << ch1 << "is a lowercase letter." << endl;
} else{
cout << ch1 << "is not a lowercase letter." << endl;
}//isupper 类似
tolower/toupper函数
tolower(char ch)可以将ch转化为小写字母,如果ch不是大写字母则不能进行操作
toupper()同理
char lowercaseCh1 = tolower(ch1);
char uppercaseCh2 = toupper(ch2);
ascii码
0-9 对应ASCII码 48-57
A-Z 对应ASCII码 65-90
a-z 对应ASCII码 97-122

!!程序设计时要注意到底时字符还是数字
例题
#include<bits/stdc++.h>
using namespace std;
char convertedCh(char ch)
{
if('a' <= ch && ch <= 'z')ch = ch - 'a' + 'A';
else if('A' <= ch && ch < 'Z')ch = ch - 'A' + 'a';
return ch;
}
int main()
{
string s;getline(cin,s);//getline函数用于从标准输入流中读取一行字符串,存储到指定的字符串变量s中。
for(auto &i : s)
i = convertedCh(i);
cout << s << '\n';
return 0;
}
错误麻烦评论区指出

浙公网安备 33010602011771号