#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(){
string s;
getline(cin,s);
int i=0;
while(s[i]!='\0')
{
s[i]=convertedCh(s[i]);
i++;
}
s[i]='\0';
cout<<s<<'\n';
return 0;
}
/*
islower()检测字符串是否为小写字母
isupper()检测字符串是否为小写字母
toupper()将小写字母转化为大写字母
tolower()将大写字母转化为小写字母
*/
用ASII码
#include<bits/stdc++.h>
using namespace std;
char convertedCh(char ch)
{
if(islower(ch)) ch=ch-'a'+'A';
else if(isupper(ch)) ch=ch-'A'+'a';
return ch;
}
int main(){
string s;
getline(cin,s);
int i=0;
while(s[i]!='\0')
{
s[i]=convertedCh(s[i]);
i++;
}
s[i]='\0';
cout<<s<<'\n';
return 0;
}
/*
islower()检测字符串是否为小写字母
isupper()检测字符串是否为小写字母
toupper()将小写字母转化为大写字母
tolower()将大写字母转化为小写字母
*/
" 0 " -- 48
" A " --64
" a " --97
1467

被折叠的 条评论
为什么被折叠?



