您的位置:首页 > 其它

数组-05. 字符串字母大小写转换(10)

2015-02-02 19:09 197 查看
输入一个以#结束的字符串,本题要求将小写字母全部转换成大写字母,把大写字母全部转换成小写字母,其它字符不变。

输入格式:

输入在一行中给出一个长度不超过40的、以#结束的非空字符串。

输出格式:

在一行中按照要求输出转换后的字符串。

输入样例:

Hello World! 123#

输出样例:

hELLO wORLD! 123


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <stdlib.h>

using namespace::std;

int main(){

int count=0;
char c[41],temp;
int i=0;
while((temp=getchar())!='#')
{
c[i]=temp;
i++;
count++;
}
for(int i=0;i<count;i++)
{
if(c[i]<='z'&&c[i]>='a')
{
c[i]=c[i]+'A'-'a';
}
else if(c[i]<='Z'&&c[i]>='A')
{
c[i]=c[i]+'a'-'A';
}
else{
}
}
c[count]='\0';
puts(c);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: