1573: math two
Time Limit: 1 sec memory limit: 128 MB
Submit: 71 solved: 27
[Submit] [Status] [web board]
Description contains n Children in a circle and numbers them from 1. The number of children starts from W. When the number of children is reported to S, the child is listed, next, report the number from the next child, and report the number of S columns. Repeat this until all the children are listed (if the total number is less than S, report the number cyclically. Input the number of children in the first line n (n <= 64). Next, enter the name of a child in each line (the name cannot exceed 15 characters). Enter W in the last line, S (W <n), separated by commas (,)
Output by person name the children are listed in order, and each row outputs a person's name
Sample input5
Xiaoming
Xiaohua
Xiaowang
Zhangsan
Lisi
2, 3 sample outputzhangsan
Xiaohua
Xiaoming
Xiaowang
Lisihint
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
Struct Node
{
Int num;
Char name [50];
Node * next;
};
Void print (node * l)
{
// L = L-> next;
While (l)
{
Printf ("% s \ n", L-> name );
L = L-> next;
}
}
Int main ()
{
Int N, W, N, I, j;
Struct node * head, * P, * q, * l;
While (scanf ("% d", & N )! = EOF)
{
Head = P = new node;
Head-> next = NULL;
P-> next = NULL;
If (N)
Scanf ("% s", p-> name); // the Start Node is empty. Error in Loop
For (I = 0; I <n-1; I ++ ){
L = new node;
Scanf ("% s", L-> name );
L-> next = NULL;
P-> next = L;
P = L;
}
P-> next = head;
Scanf ("% d, % d", & W, & N); // The error code has been changed for a long time.
P = head;
For (I = 0; I <W-1; I ++)
Q = P, P = p-> next;
// Printf ("2q: % S % s \ n", Q-> name, p-> name );
J = 0;
While (p-> next! = P)
{
For (I = 0; I <n-1; I ++ ){
Q = P, P = p-> next;
}
Printf ("% s \ n", p-> name );
Free (P );
Q-> next = p-> next;
P = Q-> next;
}
Printf ("% s \ n", p-> name );
Free (P );
}
Return 0;
}