【C语言】字符串替换

xiaoxiao2021-02-28  49

字符串替换(20 point(s))

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

原字母对应字母AZBYCXDW……XCYBZA

输入格式:

输入在一行中给出一个不超过80个字符、并以回车结束的字符串。

输出格式:

输出在一行中给出替换完成后的字符串。

输入样例:

Only the 11 CAPItaL LeTtERS are replaced.

输出样例:

Lnly the 11 XZKRtaO OeGtVIH are replaced.

 

#include <stdio.h> int main() { int i; char s[100]; gets(s); for(i=0;s[i]!='\0';i++){ if('A'<=s[i]&&s[i]<='Z') printf("%c",'M'+'N'-s[i]); else printf("%c",s[i]); } //当时考试灵机一动想到的做法!666! }

 

转载请注明原文地址: https://www.6miu.com/read-2630600.html

最新回复(0)