蓝桥杯--大小写转换(toupper,tolower使用)

来源:互联网 发布:ipad1不支持新软件 编辑:程序博客网 时间:2024/06/08 02:00
问题描述
  编写一个程序,输入一个字符串(长度不超过20),然后把这个字符串内的每一个字符进行大小写变换,即将大写字母变成小写,小写字母变成大写,然后把这个新的字符串输出。
  输入格式:输入一个字符串,而且这个字符串当中只包含英文字母,不包含其他类型的字符,也没有空格。
  输出格式:输出经过转换后的字符串。
输入输出样例
样例输入
AeDb
样例输出
aEdB
#include<stdio.h>#include<string.h>#include<algorithm>#include<cctype>using namespace std;int main(){char str[1000];scanf("%s",str);int n;n=strlen(str);int i;for(i=0;i<n;i++){if(islower(str[i]))str[i]=toupper(str[i]);elseif(isupper(str[i]))str[i]=tolower(str[i]);}for(i=0;i<n;i++)printf("%c",str[i]);return 0;}

0 0
原创粉丝点击