Joseph's ring, poj, 3750, Children Report, problem simulation

Source: Internet
Author: User
Language:DefaultData Report for children
Time limit:1000 ms   Memory limit:65536 K
Total submissions:10071   Accepted:4702

Description

There are n Children in a circle and number them in sequence from 1. Now the number is specified to start from W. When the number 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

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, S (W <n) in the last line, and separate them with commas (,).

Output

Output by person name the children are listed in order, and each row outputs a person's name

Sample Input

5XiaomingXiaohuaXiaowangZhangsanLisi2,3

Sample output

ZhangsanXiaohuaXiaomingXiaowangLisi

Source


The meaning of the question is not to mention, that is, the General Joseph ring, which requires the output of the circle order, the data is relatively small, n <= 64, directly simulate it.

A variety of small problems, tuned for a long time, too food ~~

Code:

#include <iostream>#include <cstdio>using namespace std;int vis[70];char name[70][20];int n,w,s;int main(){    int i,j;    while (~scanf("%d",&n))    {        memset(vis,0,sizeof(vis));        for (i=0;i<n;i++)            scanf("%s",name[i]);        scanf("%d,%d",&w,&s);        w--;        for (i=1;i<=n;i++)        {            int num=0,a;            while (num<s)            {                if (!vis[w])                {                    a=w;                    w++;                    num++;                }                else                    w++;                w=w%n;            }            printf("%s\n",name[a]);            vis[a]=1;        }    }    return 0;}


Joseph's ring, poj, 3750, Children Report, problem simulation

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.