7.字符串替换。输入一个以回车结束的字符串(少于 80 个字符),将其中的大写字母用下面列
出的对应大写字母替换,其余字符不变,输出替换后的字符串。试编写相应程序。
原字母 对应字母
A Z
B Y
C X
D W
……
X C
Y B
Z A
#include <stdio.h>
#include<string.h>
int main(void)
{
int i=0;
char ch,str[80];
printf("enter :");
while((ch=getchar())!='\n'){ /*输入字符串*/
str[i++]=ch;
}
str[i]='\0';
for(i=0;str[i]!='\0';i++){
if(str[i]<='Z'&&str[i]>='A'){
str[i]=('A'+'Z')-str[i]; /*转化,因为ASCII的和固定为150*/
}
}
printf("after:");
for(i=0;str[i]!='\0';i++){
putchar(str[i]); /*输出*/
}
putchar('\n');
return 0;
}