Luo Gu P1996 Joseph problems

Topic background

Joseph is a boring person! ! !

Title Description

Personal n (n <= 100) in a circle, beginning from the first number of individual packets, the number of people out of m column, and then again by the next individual packets from a start count number m of the people and then the ring , ...... and so on, until everyone turns out, please turn out the circle of people in the output number.

Input Format

n m

Output Format

A circle of numbers

Sample input and output

Input # 1
10 3
Output # 1
. 3. 6. 9 2. 7. 1. 8. 5 10. 4 

# the include <cstdio>
# the include <the iostream>
the using namespace STD;
struct Node
{
int Data;
Node * Next;
};
int main ()
{ int X, n-, m, T = 0;
CIN >> >> n-m; // IF (n-m == 0 == 0 &&) BREAK;
Node * head, tail *, * listnode;
head = tail = NULL; // list is empty initially
for ( int I = . 1; I <= m; I ++)
{= listnode new new node; // new new dynamically allocated as C ++ operator is assigned a node
listnode-> data = I; // new node data field assigned
listnode-> = head Next; // new node pointer field assignment

IF (head == NULL) = listnode head = tail; // list is empty, the first node inserting
the else
{
tail-> Next = listnode; // insert a new node at the tail of the linked list
tail = listnode; // Update list tail pointer
}
}

IF (head == NULL) return 0; // list is empty, without performing calculation processing ends
listnode = head;
the while (! listnode-> Next listnode =)
{
for ( int I = . 1; I <= n- -2; I ++)
listnode = listnode-> Next;
COUT << listnode-> next-> << Data '';
listnode-> Next = listnode-> next-> Next;
listnode = listnode-> Next;
}

COUT << listnode-> Data << endl;

return 0;
}


The list of templates question, familiar with how to build elements of the list, delete the list on it

Guess you like

Origin www.cnblogs.com/xcsj/p/11961694.html