NOIP学习之字符串:68.大小写字母互换

测试链接
总时间限制: 1000ms 内存限制: 65536kB
描述
把一个字符串中所有出现的大写字母都替换成小写字母,同时把小写字母替换成大写字母。

输入
输入一行:待互换的字符串。
输出
输出一行:完成互换的字符串(字符串长度小于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<iostream>
#include<cstring>
using namespace std;
char s[101];
int main()
{
    int i,len;
    char temp;
    gets(s);
 	len=strlen(s);
 		
	for(i=0;i<len;i++)
  	{
  		temp=s[i];
		if (s[i]<='z' && s[i]>='a')
  			temp-=32;
		if (s[i]<='Z' && s[i]>='A')
			temp+=32;		
		cout<<temp;
	}
    return 0;
}

发布了80 篇原创文章 · 获赞 0 · 访问量 768

猜你喜欢

转载自blog.csdn.net/wlxiong/article/details/104467508