Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- const int MAXN = 50;
- int queue[MAXN];
- int main() {
- int n, front, rear;
- while(scanf("%d", &n)==1 && n!=0){
- for(int i = 0; i < n; i++)
- queue[i] = i+1;
- front = 0;
- rear = n;
- while(front < rear-1) {
- front++;
- queue[rear] = queue[front];
- front++;
- rear++;
- }
- printf("%d\n", queue[front]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment