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

输入一个以#结束的字符串,本题要求将小写字母全部转换成大写字母,把大写字母全部转换成小写字母,其它字符不变。

输入格式:

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

输出格式:

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

输入样例:

Hello World! 123#

输出样例:

hELLO wORLD! 123

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <math.h>
 4 #include <string>
 5 #include <stdlib.h>
 6 
 7 using namespace::std; 
 8 
 9 int main(){
10     
11       int count=0;
12       char c[41],temp;
13       int i=0;
14       while((temp=getchar())!='#')
15       { 
16         c[i]=temp;
17         i++;
18         count++;
19       }
20       for(int i=0;i<count;i++)
21       {
22           if(c[i]<='z'&&c[i]>='a')
23           {
24               c[i]=c[i]+'A'-'a';
25           }
26           else if(c[i]<='Z'&&c[i]>='A')
27           {
28               c[i]=c[i]+'a'-'A';
29           }
30           else{
31           }
32       }
33        c[count]='';
34        puts(c);
35       return 0;
36 }
原文地址:https://www.cnblogs.com/ligen/p/4268508.html