Notice
Recent Posts
Recent Comments
Link
목록10773번 (1)
궤도
[백준] 10773번 : 제로
문제 풀이 입력을 계속 스택에 push로 쌓다가 0을 만나면 pop해주면 되겠다. 입력이 끝나면 스택에 남아있는 모든 수를 더해주자. 소스코드 #include #include using namespace std; int main() { int K, input, sum = 0; stack s; cin >> K; for (int i = 0; i > input; if (input == 0) //0이면 가장 위에 있던 수 pop으로 뺌 s.pop(); else s.push(input); } while (!s.empty()) { //스택에 쌓인 모든 수 더해줌 sum += s.top(); s.pop(); } cout
💻 현생/⛓ 알고리즘
2021. 3. 25. 18:49