//这个题看着就是简单的英文字母移动问题,但不知道为什么用一般的英文字母移动处理不了,这个题目需要用双向循环链表先将26个英文字母存入链表中,然后将待处理英文字母依次对应链表中的相应字母对应的结点,然后按题目要求左移相应次数,即完成解密。
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef struct node{
char data;
struct node *left,*right;
}Node;
int main()
{
char str[200],s[26];
int d,l,i,sum;
while(scanf("%s%d",str,&d)!=EOF)
{
s[0]='a';
for(i=1;i<26;i++)
s[i]=s[i-1]+1;
Node *h,*p,*r;
h=(Node*)malloc(sizeof(Node));
h->right=h;
h->left=h;
h->data=s[0];
r=h;
for(i=1;i<26;i++)
{
p=(Node *)malloc(sizeof(Node));
p->data=s[i];
r->right=p;
p->left=r;
p->right=h;
h->left=p;
r=p;
}
l=strlen(str);
for(i=0;i<l;i++)
{
sum=0;
r=h;
while(r->data!=str[i])
{
r=r->right;
}
while(sum!=d)
{
sum++;
r=r->left;
}
str[i]=r->data;
}
puts(str);
}
return 0;
}
01-13
3382
06-15
06-08
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交