数据结构之串的加密,此问题并不难,主要是串的基本应用。
#include
#include
#include
using namespace std;
#define MaxSize 27
//输入数组有关密码用于问题求解。
char str1[MaxSize]= {'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'};
char str2[MaxSize]= {'n','g','z','q','t','c','o','b','m','u','h','e','l','k','p','d','a','w','x','f','y','i','v','r','s','j'};
typedef struct//定义顺序串
{
char data[MaxSize];//储存输入的字符
int length;//长度
} SqString;
void StrAssign(SqString &s,char cstr[])//赋值创建串
{
int i;
for(i=0; cstr[i]!='\0'; i++)//从主函数调用赋值于结构体数组
{
s.data[i]=cstr[i];
}
s.length=i;//长度
}
void encryption(SqString &s)//加密算法
{
for(int i=0;s.data[i]!='\0';i++)//以输入的数值为最大大循环
{
for(int j=0;str1[j]!='\0';j++)//调用密码
{
if(s.data[i]==str1[j])//比较
{
s.data[i]=str2[j];//解密
break;
}
}
}
for(int j=0; j0)
{
for(i=0; i