Created
July 14, 2021 03:43
Comentário NOIC - OBI 2021 - Fase 1 P2 - Zero para cancelar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Comentário NOIC - OBI 2021 - Fase 1 P2 - Zero para cancelar | |
// Lúcio Figueiredo | |
#include <bits/stdc++.h> | |
using namespace std; | |
int main(void) | |
{ | |
int n; | |
scanf("%d", &n); | |
stack<int> stk; // declaramos a stack | |
for (int i = 1; i <= n; i++) | |
{ | |
int x; | |
scanf("%d", &x); | |
if (x == 0) stk.pop(); | |
else stk.push(x); | |
} | |
// resposta do problema | |
int ans = 0; | |
// calculamos a soma dos números que sobram | |
while (stk.size() > 0) | |
{ | |
ans += stk.top(); | |
stk.pop(); | |
} | |
printf("%d\n", ans); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment