📄 正ltj71.cpp
字号:
# include <stdio.h>
# include <string.h>
# include <malloc.h>
struct addkey
{
int no;
struct addkey *link;
};
void main()
{
int key,n,i;
static int j=0;
char cn[40],sn[40];
struct addkey *h,*u,*p;
printf("please enter a line :\ncn=");
gets(cn);
printf("please input the key:\nkey=");
scanf("%d",&key);
n=strlen(cn);
h=u=(struct addkey *)malloc(sizeof(struct addkey));
h->no=1;
for (i=2;i<=n;i++)
{
u->link=(struct addkey*)malloc(sizeof(struct addkey));
u=u->link;
u->no=i; /*第I个表元置编号I*/
}
u->link=h; /*末表元后继首表元,形成环*/
while(n)
{
for(i=1;i<key;i++) /*掠过M-1个表元*/
u=u->link;
p=u->link; /*P指向第M个表元*/
u->link=p->link; /*第M个表元从环中脱钩*/
sn[p->no-1]=cn[j++];
free(p); /*释放第M个表元占用的空间*/
n--;
}
printf("\nThe line cn is:");
puts(cn);
printf("\nThe line sn is:");
puts(sn);
printf("\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -