Joseph loop linked list contest 4

Source: Internet
Author: User

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.