ABC043B - バイナリハックイージー / Unhappy Hacking (ABC Edit)
問題:B - バイナリハックイージー / Unhappy Hacking (ABC Edit)
#include <iostream> #include <string> using namespace std; #define REP(i, n) for (int i = 0; i < (n); ++i) int main(void) { string s, ans = ""; cin.tie(0); ios::sync_with_stdio(false); cin >> s; REP(i, s.length()) { if (s[i] != 'B') { ans += s[i]; } else if (!ans.empty()) { ans.erase(ans.length() - 1); } } cout << ans << "\n"; return 0; }