Zero para cancelar

Problem Link

Solution by augusto100 pts

Code / Notes

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, x;
    cin >> N;

    vector<int> numeros;

    for (int i = 0; i < N; i++) {
        cin >> x;

        if (x == 0) {
            numeros.pop_back(); 
        } else {
            numeros.push_back(x); 
        }
    }

         int soma = 0;
        for(int i= 0;i < numeros.size(); i++){
             soma += numeros[i];
    }
    cout << soma << endl;

    return 0;
}

Last updated 2 weeks, 3 days ago


« Back to problem