sabertooth09

Untitled

Oct 3rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. const int MAXN = 50;
  4. int queue[MAXN];
  5.  
  6.  
  7. int main() {
  8.   int n, front, rear;
  9.   while(scanf("%d", &n)==1 && n!=0){
  10.       for(int i = 0; i < n; i++)
  11.           queue[i] = i+1;
  12.       front = 0;
  13.       rear = n;
  14.       while(front < rear-1) {
  15.           front++;
  16.           queue[rear] = queue[front];
  17.           front++;
  18.           rear++;
  19.       }
  20.       printf("%d\n", queue[front]);
  21.   }
  22.   return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment