Topic link
There are N people in a circle and number them clockwise as 1-N. Immediately afterwards, the person designated as M starts to report the number, and the number is reported clockwise.
The person who reports to D goes out and the next person restarts to report. According to this rule, people who report to D will be listed every time. Ask students to program to find out the order.
Input
The input includes multiple sets of test cases. For each set of use cases, the first line is an integer N, representing the number of people. N<100.
The next N lines are the names of each person. The length of the personal name does not exceed 20 consecutive strings. The last is two integers M and D separated by ",". Representatives start with M individuals, and each report D number.
Output
Output the required order
Sample Input
8
Zhao
Qian
Sun
Li
Zhou
Wu
Zheng
Wang
4,4Sample Output
Zheng
Sun
Wang
Zhou
Li
Wu
Qian
Zhao
If you use the queue method directly (there is another method, I haven't found out where the error is, I will pass it if it is destined)
#include<iostream>
#include<queue>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
queue<string> q;
string a;
for(int i=1;i<=n;i++)
{
cin>>a;
q.push(a);
}
int m,d;
char c;
cin>>m>>c>>d;
for(int i=1;i<m;i++)
{
a=q.front();
q.push(a);
q.pop();
}
while(q.size())
{
for(int i=1;i<d;i++)
{
a=q.front();
q.push(a);
q.pop();
}
cout<<q.front()<<endl;
q.pop();
}
}
return 0;
}