Creative Code

[9935번]문자열 폭발 본문

백준 문제풀이

[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;
	}
	
}

'백준 문제풀이' 카테고리의 다른 글

[14502번]연구소  (0) 2023.09.24
[14500번]테트로미노  (0) 2023.09.24
[9663번]N-Queen  (0) 2023.09.24
[9019번]DSLR  (0) 2023.09.24
[7662번]이중 우선순위 큐  (0) 2023.09.24