Advertisement
libchm

KO urself

Jul 9th, 2016
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct node { int key; struct node *next; };
  5.  
  6. int main(int argc, char** argv)
  7. {
  8.     int i, N, M;
  9.     struct node *t, *x;
  10.    
  11.     scanf("%d %d", &N, &M);
  12.    
  13.     t = (struct node *) malloc(sizeof *t);
  14.     t->key = 1; x = t;
  15.    
  16.     for(i = 2; i <= N; i++){
  17.         t->next = (struct node *) malloc(sizeof *t);
  18.         t = t->next;
  19.         t->key = i;
  20.     }
  21.     t->next = x;
  22.    
  23.     while(t != t->next){
  24.         for(i = 1; i < M; i++){ t = t->next;};
  25.         printf("%d", t->next->key);
  26.         x = t->next;
  27.         t->next = t->next->next;
  28.         free(x);
  29.     }
  30.    
  31.     printf("%d\n", t->key);
  32.    
  33.     return 0;
  34.    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement