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 nameSample 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