View Code of Problem 3309

#include<iostream>
#include<queue>
#include<string>
using namespace std;
struct node{
	string name;
	int id;
};
int main(){
	int n;cin>>n;
	string s;
	queue<struct node>q;
	struct node x;
	getchar();
	for(int i=1;i<=n;++i){
		getline(cin,s);
		x.name=s;
		x.id=i;
		q.push(x);
	}
	int w,l,d=1;
	scanf("%d,%d",&w,&l);
	w--;
	while(w--){
		x=q.front();
		q.push(x);
		q.pop();
	}
	while(q.size()>=l){
		if(d%l==0){
			cout << q.front().name<<endl;
			q.pop();
			d=1;
		}
		else{
			d++;
			x=q.front();
			q.pop();
			q.push(x);
		}
	}
	while(!q.empty()){
		cout<<q.front().name<<endl;
		q.pop();
	}
}

Double click to view unformatted code.


Back to problem 3309