我的代码
#include<vector>
#include<iostream>
using namespace std;
class LeaguePicks
{
public:
vector<int> returnPicks(int position, int friends, int picks);
};
vector <int> LeaguePicks::returnPicks(int position, int friends, int picks)
{
vector <int> receive_picks;
int a[] = {(friends - position) * 2 + 1, (position - 1) * 2 + 1};
if (picks >= position) {
receive_picks.push_back(position);
int index = position;
int i = 0;
while(true) {
index += a[i];
if (index <= picks) {
if (i == 0) i = 1;
else i = 0;
receive_picks.push_back(index);
}
else break;
}
}
return receive_picks;
}
void main()
{
LeaguePicks test;
vector <int> result = test.returnPicks(3, 6, 15);
for(int i = 0; i < result.size(); i++) {
cout<<result.at(i)<<" ";
}
cout<<endl;
result = test.returnPicks(1, 1, 10);
for(int i = 0; i < result.size(); i++) {
cout<<result.at(i)<<" ";
}
cout<<endl;
result = test.returnPicks(1, 2, 39);
for(int i = 0; i < result.size(); i++) {
cout<<result.at(i)<<" ";
}
cout<<endl;
result = test.returnPicks(5, 11, 100);
for(int i = 0; i < result.size(); i++) {
cout<<result.at(i)<<" ";
}
cout<<endl;
}