字符变换问题
“a”能用“e”来代替现在他给出了字母的替换规则,如下所示,A被E替换,B被C替换,依次类推。
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
E C F A J K L B D G H I V W Z Y M N O P Q R S T U X
a b c d e f g h i j k l m n o p q r s t u v w x y z
e r w q t y g h b n u i o p s j k d l f a z x c v m
本题包括多组测试数据。每组测试数据为一行:为仅由字母和空格组成的字符串(空格不变)。输入以单行“#”结束
样例输入
Ilttabaje zaujljg
#
样例输出
Different meaning
代码:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,j,k;
char letter[4][26]={{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'},{'E','C','F','A','J','K','L','B','D','G','H','I','V','W','Z','Y','M','N','O','P','Q','R','S','T','U','X'},{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'},{'e','r','w','q','t','y','g','h','b','n','u','i','o','p','s','j','k','d','l','f','a','z','x','c','v','m'}};
char str[400];
while(1)
{
gets(str);
if(str[0]=='#')
exit(-1);
for(i=0;str[i]!='\0';i++)
{
for(j=0;j<=2;j+=2)
for(k=0;k<26;k++)
if(str[i]==letter[j][k])
{
str[i]=letter[j+1][k];
break;
}
}
puts(str);
}
}
OJ上显示错误:
使用了系统禁止的操作系统调用,看看是否越权访问了文件或进程等资源
缓冲区溢出,检查是否有字符串长度超出数组的情况