习题7-7 字符串替换 (15分)

本题要求编写程序,将给定字符串中的大写英文字母按以下对应规则替换:

原字母对应字母
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>
int main(void)
{
    char a[80];
    char ch='0';
    int i,j;
    i=0;
    while(ch!='\n'){
        scanf("%c",&ch);
        a[i++]=ch;        //输入回车,也被记录。 
    }
    
    for(j=0;j<i-1;j++){
        if(a[j]>='A'&&a[j]<='Z')
                a[j]='A'+'Z'-a[j];
        printf("%c",a[j]); 
    }
    
    return 0;
}

 



posted on 2020-03-31 21:58  Kimsohyun4ever  阅读(3595)  评论(0编辑  收藏  举报