描述
把一个字符串中所有出现的大写字母都替换成小写字母,同时把小写字母替换成大写字母。
输入
输入一行:待互换的字符串。
输出
输出一行:完成互换的字符串(字符串长度小于80)。
样例输入
If so, you already have a Google Account. You can sign in on the right.
样例输出
iF SO, YOU ALREADY HAVE A gOOGLE aCCOUNT. yOU CAN SIGN IN ON THE RIGHT.
这道题,跟上一题一个思路,这里不多说了
同样的,两种方法
#include<bits/stdc++.h>
using namespace std;
int main(){
string a;
getline(cin,a);
for(int i=0;i<a.size();i++){
if(a[i]>='A'&&a[i]<='Z'){a[i]+=32;continue;}
if(a[i]>='a'&&a[i]<='z') a[i]-=32;
}
cout<<a;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
string a,b;
getline(cin,a);
for(int i=0;i<a.size();i++){
if(a[i]>='A'&&a[i]<='Z') b+=a[i]+32;
else if(a[i]>='a'&&a[i]<='z') b+=a[i]-32;
else b+=a[i];
}
cout<<b;
return 0;
}