本題要求編寫程序,將給定字符串中的大寫英文字母按以下對應規則替換:
原字母 | 對應字母 |
---|---|
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; }