Description
输入多个字符串,对其进行加密。加密规则为:
A→Z a→z
B→Y b→y
C→X c→x
.....................
即将字符串中的第i个大写或小写英文字母变成相应的第(26-i+1)个大写或小写字母,其他字符不变。
Input
先输入一个正整数n,表示后面有n个字符串(最大长度不超过100)。然后依次输入n个字符串。
Output
依次输出n个加密后的字符串。
Sample Input
2 abcABC ABCabc
Sample Output
zyxZYX ZYXzyx
HINT
Append Code
废话不说,直接上代码
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <ctype.h> #define MAX_STR_LEN 101 int main() { int n; char a[110]= {0}; scanf("%d",&n); getchar(); for(int i=0; i<n; i++) { gets(a); for(int j=0; j<strlen(a); j++) { if(islower(a[j])) a[j]+=((26-2*(a[j]-'a')-1));//根据字母的大小写分类 else if(isupper(a[j])) a[j]+=((26-2*(a[j]-'A')-1)); } puts(a); memset(a,'\0',sizeof(a)); } return 0; }
注意:在scanf的后面要加一个getchar()来吸收换行符;
同时注意数组清零
07-19
1620
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-18
2万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交