본문 바로가기
Algorithm/📖Baekjoon

#10773 제로

by yewoneeee 2022. 4. 25.

# 문제

# 입력 및 출력

# 풀이

최근 숫자를 지운다고 했으니까 lifo 구조인 스택을 사용하면 됨

#include <iostream>
#include <stack>
using namespace std;

int main() {
	int k, result = 0;
	cin >> k;
	stack<int> cash;
	for (int i = 0; i < k; i++) {
		int tmp;
		cin >> tmp;
		if (tmp == 0) cash.pop();
		else cash.push(tmp);
	}
	while (!cash.empty()) {
		result += cash.top();
		cash.pop();
	}
	cout << result << endl;
}

'Algorithm > 📖Baekjoon' 카테고리의 다른 글

#1874 스택 수열  (0) 2022.04.27
#2164 카드2  (0) 2022.04.26
#2941 크로아티아 알파벳  (0) 2022.04.24
#5622 다이얼  (0) 2022.04.24
#1920 수 찾기  (0) 2022.04.24

댓글