字符串大小写逆置(神奇的ascll码)

来源:互联网 发布:数据部门团建出行标语 编辑:程序博客网 时间:2024/06/05 09:50

自己写的第一个稍微按要求来的程序


描述:

给定一个字符串,全部由英文字母组成 ,要求把该字符串的中的大写字母改为小写,小写字母改为大写。字符长度不超过20
Input a string, it is compose of letters, you must be change all the uppercase letters to lowercase and all the lowercase to uppercase. The string length is no more then 20


输入:

一个长度不超过20的字符串
Input a string, the string length is no more then 20


输出:

输出处理完后的字符串,最后输出回车
Output the reversed string.


输入样例:

HelloWorld


输出样例:

hELLOwORLD 

//1034字符串大小写逆置#include<iostream>#include<cstdio>

using namespace std;

int main(){ int i,j;  char A[21];  gets(A);  for(i=0;i<20;i++) {  if(A[i]=='\0')//限制范围   {   j=i;   break;  } }  for(i=0;i<j;i++)//逆置大小写  {  if(A[i]>=65&&A[i]<=90)  {   A[i]+=32;  }  else if(A[i]>=97&&A[i]<=122)  {   A[i]-=32;  } }  puts(A);  return 0; }



原创粉丝点击