CSP 201712-2游戏

#include <stdio.h>
struct node
{
int num;
struct node *next;
};
int main()
{
struct node *L,*p,*pre,*r;
int n,k,i,j;
scanf("%d%d",&n,&k);
L=(struct node *)malloc(sizeof(struct node));
L->num=1;r=L;
for(i=2;i<=n;i++)
{
p=(struct node *)malloc(sizeof(struct node));
p->num=i;
r->next=p; r=p;
}
r->next=L;
pre=r;p=L;
i=1;j=0;
while(j<=n-1)
{
while(i%k!=0&&i%10!=k)
{
pre=p;
p=p->next;
i++;
}
if(i%k == 0 || i%10==k)
{
pre->next=p->next;
free§;
j++;
p=pre->next;i++;
}
}
printf("%d",p->num);
return 0;
}

相关文章:

  • 2022-02-03
  • 2022-12-23
  • 2021-05-11
  • 2021-09-08
  • 2022-01-05
  • 2022-01-12
  • 2021-07-30
  • 2021-12-16
猜你喜欢
  • 2022-12-23
  • 2021-12-15
  • 2021-07-14
  • 2022-02-11
  • 2022-12-23
  • 2021-10-09
  • 2022-12-23
相关资源
相似解决方案