#include <bits/stdc++.h>
using namespace std;
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
stack<int> st;
while (N--)
{
string s;
cin >> s;
if (s == "push")
{
int num;
cin >> num;
st.push(num);
}
else if (s == "top")
{
cout << st.top() << '\n';
}
else if (s == "size")
{
cout << st.size() << '\n';
}
else if (s == "empty")
{
if (st.empty())
{
cout << 1 << '\n';
}
else
{
cout << 0 << '\n';
}
}
else //pop
{
if (st.empty())
{
cout << -1 << '\n';
}
else
{
cout << st.top() << '\n';
st.pop();
}
}
}
}
이게 런타임 오류 뜨는거고
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
stack<int> S;
while(n--){ // n번 반복
string c;
cin >> c;
if(c=="push"){
int t;
cin >> t;
S.push(t);
}
else if(c=="pop"){
if(S.empty()) cout << -1 << '\n';
else{
cout << S.top() << '\n';
S.pop();
}
}
else if(c=="size")
cout << S.size() << '\n';
else if(c=="empty")
cout << (int)S.empty() << '\n';
else{ // top
if(S.empty()) cout << -1 << '\n';
else cout << S.top() << '\n';
}
}
}
이게 통과코드인데 무슨 if 문에 순서가 다르다고 통과되고 안되는건 뭐고 ㅅㅂ
테스트케이스 하나 있는거 vsc에선 똑같은데 백준은 통과안되서 한시간동안 고통 받앗노
댓글 0