View Code of Problem 3309

#include<iostream>
#include<string>
#include<stdio.h>
#include<vector>
using namespace std;

void fun(vector<string> &str, int &start, int s,int len) {
	int index = start + s - 1;
	index = index >= len ? index % len : index;
	cout << str[index] << endl;
	str.erase(str.begin() + index);
	start = index >= (len -1) ? index % (len - 1) : index;
}

int main() {
	int n;
	vector<string> str;
	string temp;
	int w, s;
	char c;
	cin >> n;
	getchar();
	for (int i = 0;i < n;i++) {
		getline(cin, temp);
		str.push_back(temp);
	}
	cin >> w >> c >> s;
	int start = w-1;
	while(n--){
		if (n == 0) {
			break;
		}
		fun(str, start, s, n+1);
	}
	cout << str[0] << endl;
}

Double click to view unformatted code.


Back to problem 3309