회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
2
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
10828번 - 스택
BaaaaaaaaaaarkingDog
C++14
#include <bits/stdc++.h> using namespace std; const int MX = 10000007; int dat[MX]; int pos; // 알아서 0으로 초기화 됨 void push(int val){ dat[pos++] = val; // step 1, 2 } void pop(){ pos--; } int top(){ return dat[pos-1]; } int main(void) { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; while(n--){ // n번 반복 string c; cin >> c; if(c=="push"){ int t; cin >> t; push(t); } else if(c=="pop"){ if(pos == 0) cout << -1 << '\n'; else{ cout << top() << '\n'; pop(); } } else if(c=="size") cout << pos << '\n'; else if(c=="empty") cout << (int)(pos == 0) << '\n'; else{ // top if(pos == 0) cout << -1 << '\n'; else cout << top() << '\n'; } } }
결과
메모리
시간
코드 길이
맞았습니다!!
41088
0
798