There are 2 deck of cards ( deckA and deckB ), deckA has n cards, which are numerated from 1 to n from top to bottom, deckB is empty. Three rules need to be applied:
1) Put the top card from deckA on top of deckB 2) Switch the top card from deckA with the bottom card, do the same with deckB 3) If there are cards left in deckA, continue doing first two rules
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> deckA;
vector<int> deckB;
for (int i = 0; i < n; i++) {
deckA.push_back(i+1);
}
for (int i = 0; i < n; i++) {
deckB.insert(deckB.begin(), deckA[0]);
deckA.erase(deckA.begin());
rotate(deckA.begin(), deckA.begin() + 1, deckA.end());
rotate(deckB.begin(), deckB.begin() + 1, deckB.end());
}
for (int i = 0; i < n; i++) {
cout << deckB[i];
if (i != n-1) {
cout << ",";
}
}
}
I'm getting expression: cannot seek vector iterating after end. I'm pretty sure I'm rotating wrong. Any help is appreciated.
Aucun commentaire:
Enregistrer un commentaire