Think:
也开学一周了~~~开学的第一篇blog, 这道题是水题,只需判断 字符是否为 大写字母即可,然后就根据对应关系输出就好了!也是PTA的模拟题~
题目
本题要求编写程序,将给定字符串中的大写英文字母按以下对应规则替换:
原字母 对应字母
A Z
B Y
C X
D W
… …
X C
Y B
Z A
输入格式:
输入在一行中给出一个不超过80个字符、并以回车结束的字符串。
输出格式:
输出在一行中给出替换完成后的字符串。
输入样例:
Only the 11 CAPItaL LeTtERS are replaced.
输出样例:
Lnly the 11 XZKRtaO OeGtVIH are replaced.
#include<stdio.h>
#include<string.h>
int main()
{
char str[100];
int d;
gets(str);
d = strlen(str);
int i;
for (i = 0;i <= d - 1;i ++)
{
if (str[i] >= 'A' && str[i] <= 'Z')
{
char c = str[i];
int d = c - 'A';
str[i] = 'A' + 'Z' - c;
}
}
puts(str);
return 0;
}