翻译密码

来源:百度知道 编辑:UC知道 时间:2024/05/29 21:32:52
将A变成E,a变成e,W变成A。。。即将原字母变成之后的第四个字母,非字母字符不变。如“Wonderful!”转换为“Asrhivjpy!”
输入一行字符,要求输出其相应的密码。

我有一点想法 就是ASCⅡ码转变
再有一个循环嵌套 但是小弟才疏 W转换A这步和以后的小写之间的转换不会写在一起表示 而且非字母字符不转变。 难道还有一段判断语句?

#include<stdio.h>
#include<string.h>
#define max 30
char change(char temp)
{
if((temp>='a'&&temp<='z')||(temp>='A'&&temp<='Z'))
{
if(temp>='w'&&temp<='z')
{
temp=(temp+4)%123+97;
return temp;
}
else if(temp>='W'&&temp<='Z')
{
temp=(temp+4)%91+65;
return temp;
}
else
{
temp=temp+4;
return temp;
}
}
else
return temp;
}
void main()
{
int i,n;
char ch[max];
printf("请输入一个字符串:");
gets(ch);
n=strlen(ch);
for(i=0;i<n;i++)
{
ch[i]=change(ch[i]);
}
puts(ch);
printf("\n");
}

你这个程序用switch或者if else语句来实现

遍历字符串的所有字符

然后分别判断各自属于什么类型的字符 进行相应转换即可

for(i=0;a[i]!='\0';i++)
{