#include<stdio.h>
#include<stdlib.h>
typedef struct student{
int number;
struct student*next;
}node;
node *create(int n);
void function(node *head,int num);
int main()
{
int n,m=3;
node *head;
scanf("%d",&n);
head=create(n);
function(head,m);
return 0;
}
node* create(int n)
{
node *head;
head=(node*)malloc(sizeof(node));
head->next=NULL;
node *q=head;
node *p;
for(int i=1;i<=n;i++)
{
p=(node*)malloc(sizeof(node));
p->number=i;
p->next=q->next;
q->next=p;
q=p;
}
q->next=head->next;
return head;
}
void function(node*t,int n)
{
node*p=t->next;
free(t);
node*q=NULL;
while(p->next !=p)
{
for(int i=1;i<=n-2;i++)
{
p=p->next;
}
q=p->next;
p->next=q->next;
p=p->next; //移动到报号起点
free(q);
}
printf("%d",p->number);
return ;
}
0.0分
0 人评分
最长单词 (C语言代码)浏览:1380 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:640 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:600 |
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C语言代码)浏览:613 |
WU-输出九九乘法表 (C++代码)浏览:1672 |
字符逆序 (C语言代码)浏览:646 |
1126题解浏览:596 |
局部变量作函数返回值的问题浏览:981 |
矩形面积交 (C语言代码)浏览:1314 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:492 |