View Code of Problem 3309

#include<iostream>
#include<queue>
using namespace std;
struct Chi{
	string name;
	int id;
};
int main(){
	int N;
	while(cin>>N){
		Chi ar[70];
		for(int i=1;i<=N;i++){
			cin>>ar[i].name;
			ar[i].id=1;
		}
		getchar();
		string str;
		getline(cin,str);
		int w,s;
		int it=str.find(',');
		w=stoi(str.substr(0,it));
		s=stoi(str.substr(it+1));
		//cout<<w<<' '<<s<<endl;
		queue<Chi>q;
		for(int i=w,j=0;j<N;j++){
			q.push(ar[i]);
			//cout<<ar[i].name<<endl;
			i++;
			if(i>N){
				i=1;
			}
		}
		int num=1;
		while(!q.empty()){
			Chi cur=q.front();
			//cout<<cur.name<<endl;
			q.pop();
			if(num==s){
				cout<<cur.name<<endl;
				num=1;
			}
			else{
				num++;
				q.push(cur);
			}
		}
	}
}
/*
Main.cc: In function `int main()':
Main.cc:22: error: `stoi' undeclared (first use this function)
Main.cc:22: error: (Each undeclared identifier is reported only once for each function it appears in.)
*/

Double click to view unformatted code.


Back to problem 3309