#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
char str[100];
char mp[100]={"ngzqtcobmuhelkpdawxfyivrsj"};
typedef struct snode
{
char data;
struct snode *next;
} LinkStrNode; //声明链串节点类型
void StrAssign(LinkStrNode *&s,char cstr[]) //字符串常量cstr赋给串s
{
LinkStrNode *r,*p;
s=(LinkStrNode *)malloc(sizeof(LinkStrNode));
r=s; //r始终指向尾节点
for (int i=0;cstr[i]!='\0';i++)
{ p=(LinkStrNode *)malloc(sizeof(LinkStrNode));
p->data=cstr[i];
r->next=p;r=p;
}
r->next=NULL;
}
void DispStr(LinkStrNode *s) //输出串
{
LinkStrNode *p=s->next;
while (p!=NULL)
{ printf("%c",mp[p->data-'a']);
p=p->next;
}
printf("\n");
}
int main(){
cout<<"输入原文串:";
cin>>str;
cout<<"加密解密如下:"<<endl;
printf("原文串:");
cout<<str<<endl;
printf("加密串:");
LinkStrNode *s;
StrAssign(s,str);
DispStr(s);
printf("解密串:");
cout<<str<<endl;
return 0;
}
第八次试验
最新推荐文章于 2023-04-22 00:19:04 发布