BOJ-2812
08 Jul 2021간단한 스택 문제로 시간이 없다는 핑계로 전에 풀었던 문제를 리뷰했다…
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int size, erase;
stack<int> st;
string num;
cin >> size >> erase;
cin >> num;
for(int i=0; i<size ; ++i){
while(!st.empty() && num[i]-'0'>st.top() && erase>0){
st.pop();
erase--;
}
st.push(num[i]-'0');
}
while(erase>0){
st.pop();
--erase;
}
stack<int> ans;
while(!st.empty()){
ans.push(st.top());
st.pop();
}
while(!ans.empty()){
cout << ans.top();
ans.pop();
}
cout << "\n";
return 0;
}
미루는 습관 버릇을 고치자… 내일 금요일이니까 조금만 힘내쟈,,,, 주말엔 더 난이도 있는거 풀기로 약속 ㅜㅜ