习题7-7 字符串替换
Description
本题要求编写程序,将给定字符串中的大写英文字母按以下对应规则替换:
原字母 | 对应字母 |
---|---|
A | Z |
B | Y |
C | X |
D | W |
… | … |
X | C |
Y | B |
Z | A |
Input
输入在一行中给出一个不超过80个字符、并以回车结束的字符串。
Output
输出在一行中给出替换完成后的字符串。
Sample Input 1
Only the 11 CAPItaL LeTtERS are replaced.
Sample Output 1
Lnly the 11 XZKRtaO OeGtVIH are replaced.
#include <stdio.h>
#include <string.h>
int main(int argc, char const *argv[])
{
/* code */
char str[80];
int len;
gets(str);
len=strlen(str);
int i=0;
for (i = 0; i < len; ++i)
{
/* code */
if (str[i]>='A'&&str[i]<='Z')
{
/* code */
str[i]='A'+'Z'-str[i];
}
}
printf(str);
return 0;
}