백준 문제풀이
[9935번]문자열 폭발
빛하루
2023. 9. 24. 17:40
https://www.acmicpc.net/problem/9935
9935번: 문자열 폭발
첫째 줄에 문자열이 주어진다. 문자열의 길이는 1보다 크거나 같고, 1,000,000보다 작거나 같다. 둘째 줄에 폭발 문자열이 주어진다. 길이는 1보다 크거나 같고, 36보다 작거나 같다. 두 문자열은 모
www.acmicpc.net
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
vector<char>s;
string str, bomb;
cin >> str >> bomb;
string answer = "";
for (int i = 0; i < str.size(); i++) {
s.push_back(str[i]);
if (s.size() >= bomb.size()) {
bool check = true;
for (int j = 0; j < bomb.size(); j++) {
if (s[s.size() - bomb.size() + j] != bomb[j]) {
check = false;
}
}
if (check == true) {
for (int j = 0; j < bomb.size(); j++) {
s.pop_back();
}
}
}
}
if (s.empty()) {
cout << "FRULA";
}
else {
for (int i = 0; i < s.size(); i++) {
answer += s[i];
}
cout << answer;
}
}