code for fun

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
#include<stdio.h>
#include
<stdlib.h>

typedef 
struct node* link;
struct node{int item; link next;};

int main()
{  
   
int i,N,M;
   scanf(
"%d%d",&N,&M);
   link t
=malloc(sizeof *t),x=t;
   t
->item=1;t->next=t;
   
for(i=2; i<=N; i++){
         x
=(x->next=malloc(sizeof *x));
         x
->item=i; x->next=t;
       }
       
      
while(x!=x->next){
           
for(i=1; i<M; i++) x=x->next;
           x
->next=x->next->next;N--;
          
          }
          printf(
"%d\n",x->item);
      
return 0;
}

 

posted on 2011-04-26 15:46  xueda120  阅读(115)  评论(0编辑  收藏  举报