文章
47
粉丝
109
获赞
9
访问
31.6k
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
char s[105];
gets(s);
int len = strlen(s);
for (int i = 0; i < len; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
s[i] += 3;
if (s[i] > 'z')s[i] -= 26;
}
else if (s[i] >= 'A' && s[i] <= 'Z') {
s[i] += 3;
if (s[i] > 'Z') s[i] -= 26;
}
else {
continue;
}
}
puts(s);//输出字符串
return 0;
}
第二种
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
char s[105];
gets(s);//为了不让空格干扰而不使用scanf
int len = strlen(s);
for (int i = 0; i < len; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
s[i] = 'A'+(s[i] - 'A' + 3)%26;//先算加三后看是否超出,超出取余
}
if (s[i] >= 'a' && s[i] <= 'z') {
s[i] = 'a' + (s[i] - 'a' + 3) % 26;
}
}
puts(s);
return 0;
}
登录后发布评论
暂无评论,来抢沙发