#include<stdio.h>
#include<stdlib.h>
#define MAX 100
char str[MAX];
typedef int datatype;
typedef struct snode{
datatype info;
struct snode *next;
} StackNode, *LinkStack;
LinkStack Init( )
{ LinkStack top;
top=(LinkStack)malloc(sizeof(StackNode));
top->next=NULL;
return top;
}
int Empty (LinkStack top)
{ return top->next==NULL;
}
void Push (LinkStack top, datatype x)
{ LinkStack p;
p=(LinkStack)malloc(sizeof(StackNode));
p->info=x;
p->next=top->next;
top->next=p;
}
datatype Pop (LinkStack top)
{ LinkStack p; datatype x;
if ( Empty (top) )
{
printf("\nThe sequence stack is empty!");
exit(1);
}
p=top->next;
x=p->info;
top->next=p->next;
free(p);
return x;
}
datatype GetTop (LinkStack top)
{
if ( Empty(top) )
{
printf("\nThe sequence stack is empty!");
exit(1);
}
return top->next->info;
}
void readData()
{
FILE *fp;
if((fp=fopen("a.txt","r"))==NULL)
{
printf("can not open file");
exit(1);
}
fscanf(fp,"%s",str);
puts(str);
fclose(fp);
}
int main()
{
int n;
int i;
printf("请输入密码:");
scanf("%d",&n);
readData();
for(i=0;str[i]!='\0';i++)
{
str[i]=str[i]+n;
}
str[i]='\0';
LinkStack s;
s=Init();
for(i=0;str[i]!='\0';i++)
{
Push(s,str[i]);
}
i=0;
while(!Empty (s))
{
str[i]=Pop(s);
i++;
}
str[i]='\0';
printf("加密结果为:\n");
for(i=0;str[i]!='\0';i++)
{
printf("%c",str[i]);
}
printf("\n");
return 0;
}