1 islower/issupper函数
2 tolower/toupper
3 ascii码
大小写转换代码(库函数)
#include<bits/stdc++.h>
using namespace std;
char convertedCh(char ch)
{
if(islower(ch))
{
ch=toupper(ch);
}
else if(isupper(ch))
{
ch=tolower(ch);
}
return ch;
}
int main()
{
ios::sync_with_stdio,cin.tie(0),cout.tie(0);
string s;
getline(cin,s);
for(auto &i:s)
i=convertedCh(i);
cout << s << '\n';
return 0;
}
大小写转换代码(ascii)
#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()
{
ios::sync_with_stdio,cin.tie(0),cout.tie(0);
string s;
getline(cin,s);
for(auto &i:s)
i=convertedCh(i);
cout << s << '\n';
return 0;
}