#競技プログラミングで
ABCの43回目のB問題 において,自分はstackを使って以下のように解答をしたのですが,
#include <iostream> #include <algorithm> #include <cstdio> #include <cmath> #include <string> #include <vector> #include <stack> #include <set> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); string s; stack<char> ans; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 0) ans.push(0); if (s[i] == 1) ans.push(1); if (s[i] == 'B' && !ans.empty()) ans.pop(); } while (!ans.empty()){ cout << ans.top() << endl; ans.pop(); } return 0; }
何かしらを間違っているようで
01B0
のように入力すると
segmentation fault: 11
と出てきてしまいます.
よかったら何が間違っているかと解決方法を教えていただきたいです.
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。