-
[PS] 백준 9935번: 문자열 폭발문제해결 2023. 11. 20. 15:58
int pos = str.find(bomb); while (pos != string::npos) { str.erase(str.begin() + pos, str.begin() + pos + bomb.size()); pos = str.find(bomb); }
혹시나 싶어 이런식으로 날먹을 시도해봤는데, 역시 안되더라
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define FOR(i, N) for (int i = 0; i < static_cast<long long>(N); i++) #define FORL(e, S) for (auto& e : S) string str, bomb; vector<char> v; int main() { cin >> str >> bomb; FORL(e, str) { v.push_back(e); if (v.size() < bomb.length()) continue; bool should_pop = true; FOR(i, bomb.length()) { if (v[v.size() - 1 - i] != bomb[bomb.length() - 1 - i]) { should_pop = false; break; } } if (should_pop) FOR(i, bomb.length()) v.pop_back(); } if (v.size()) { FORL(e, v) cout << e; cout << endl; } else { cout << "FRULA" << endl; } }
'문제해결' 카테고리의 다른 글
[PS] 백준 23253번: 자료구조는 정말 최고야 (0) 2023.11.28 [PS] 백준 9251번: LCS, 백준 5582번: 공통 부분 문자열 (2) 2023.11.20 [PS] 백준 11689번: GCD(n, k) = 1 (1) 2023.11.20 [PS] 백준 17390번: 이건 꼭 풀어야 해! (입출력 관련) (1) 2023.11.09 [PS] 백준 1016번: 제곱 ㄴㄴ 수 (0) 2023.11.09