From 75defbfa2e42030eb42a64f5c246d430972218b6 Mon Sep 17 00:00:00 2001 From: Evan Carr Date: Wed, 14 Feb 2024 18:00:36 -0500 Subject: [PATCH] [C++] Add solution for Even Up Solitaire --- Solutions/Even Up Solitaire/evenup.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Solutions/Even Up Solitaire/evenup.cpp diff --git a/Solutions/Even Up Solitaire/evenup.cpp b/Solutions/Even Up Solitaire/evenup.cpp new file mode 100644 index 00000000..81b275e2 --- /dev/null +++ b/Solutions/Even Up Solitaire/evenup.cpp @@ -0,0 +1,23 @@ +#include +#include + +using namespace std; + +int main() { + int n; + cin >> n; + + stack 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; +} \ No newline at end of file