Zero para cancelar
Problem LinkSolution by Mr.Olimpia — 100 pts
Code / Notes
#include <bits/stdc++.h>
using namespace std;
/*int dig(int N) {
int ans = 1;
while (N > 10) {
N /= 10;
ans++;
}
return ans;
}*/
int main() {
int N;
cin >> N;
// vector<int> v; -> {}
// vector<int> v(N, 0); -> {0, 0, 0, 0, 0, 0}
// v[i] = 3 -> {0, 0, 3, 0, 0, 0};
// v.push_back(3) -> {0, 0, 0, 0, 0, 0, 3};
// v.pop_back() -> {0, 0, 0, 0, 0};
vector<int> v;
for(int i=0; i<N; i++){
int x;
cin >> x;
if(x==0){
v.pop_back();
}
else{
v.push_back(x);
}
// Escreve o v inteiro
}
int ans=0;
for(int i=0; i<v.size(); i++){
ans=ans + v[i];
}
cout << ans;
}
Last updated 2 weeks, 3 days ago