作业帮 > 综合 > 作业

用C语言编写一个加密程序字母对照的 原字母a b c d e i k ,w 加密后a w k ,i a b c e

来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/04/28 17:19:46
用C语言编写一个加密程序字母对照的 原字母a b c d e i k ,w 加密后a w k ,i a b c e
用C语言编写一个加密程序字母对照的 原字母a b c d e i k ,w 加密后a w k ,i a b c e
可以考虑用结构来解决这个问题,代码如下:
#include
struct table
{
\x05char input,output;
};
struct table translate[]=
{
\x05'a','a','b','w','c','k','d',',','e','a','k','b',',','c','w','e'
}; //建立加密对照表
int main()
{
\x05char ch;
\x05struct table *p,*pend;
\x05pend=&translate[sizeof(translate)/sizeof(struct table)-1];
\x05while((ch=getchar())!='\n')
\x05{
\x05\x05for(p=translate;p->input!=ch&&p!=pend;p++); //将p调整至对应的输出字符
\x05\x05\x05if(p->input==ch)
\x05\x05\x05\x05putchar(p->output); //输出对应的加密后的字符
\x05\x05\x05else
\x05\x05\x05\x05purchar(ch);
\x05}
}