20250302-Rain
1. 字符串
/*
1. 大小写转换
设计一个程序, 输入一行字符串, 将其中大写转为小写, 小写转为大写. 其余字符不变
(字符串长度<100)
样例输入: hELLO wORLD!
样例输出: Hello World!
*/
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string S;
cout << "Please input 'S': ";
// 输入字符串,可以包含空格
getline(cin, S);
// // 遍历 S 的每一个字符,单独判断
// // 手撸
// for(auto &c : S)
// {
// if(c >= 'a' && c <= 'z')
// {
// c = c - 'a' + 'A';
// }
// else if(c >= 'A' && c <= 'Z')
// {
// c = c - 'A' + 'a';
// }
// }
// 内置方法
for(auto &c : S)
{
if(islower(c))
{
c = toupper(c);
}
else if(isupper(c))
{
c = tolower(c);
}
}
cout << S << endl;
return 0;
}2. 嵌套循环
3. 螺旋矩阵
Last updated