Skip to content

Commit

Permalink
[C++] Add solution for Even Up Solitaire
Browse files Browse the repository at this point in the history
  • Loading branch information
ejrcarr committed Feb 17, 2024
1 parent 65d394b commit 75defbf
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Solutions/Even Up Solitaire/evenup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>
#include <stack>

using namespace std;

int main() {
int n;
cin >> n;

stack<int> cards;
while(n--) {
int card;
cin >> card;
if(!cards.empty() && !((cards.top() + card) % 2)) {
cards.pop();
continue;
}
cards.push(card);
}

cout << cards.size();
return 0;
}

0 comments on commit 75defbf

Please sign in to comment.