알고리즘_백준/문자열
acmicpc_9935 (문자열 폭발)
giron
2020. 10. 27. 10:36
728x90
#include <iostream>
#include <string.h>
#include <cstring>
#include <vector>
using namespace std;
string c;
string s;
string boom;
int main() {
cin.sync_with_stdio(false);
cin.tie(NULL);
int del = 0;
cin >> c;
cin >> boom;
int i;
int last = boom.length() - 1;//boom의 마지막 문자
for (i = 0; i < c.length(); ++i) {
s += c[i];
if (boom[last] == c[i] && i>=last) {
del = 0;
for (int j = 1; j < boom.length(); ++j) {
if (boom[last - j] != s[s.size()-1 - j]) {
del = 1;
}
}
if (del == 0) {
for (int j = 0; j < boom.length();++j) {
s.pop_back();
}
}
}
}
if (s.size() == 0) {
cout << "FRULA";
}
else {
cout << s;
}
}
정말 내가 폭발해 버릴 뻔했던 문제.. 시간초과의 늪에서 빠져나오는데 너무 오래걸렸다.. 이 문제를 풀면서 vector보단 string이 빠르다는걸 char[]보다 string이 빠르다는걸 느꼈다.. 그저 string으로 바꿨을 뿐인데 2%->100%까지 바뀌다니.. 원인에 대해서 좀더 연구해 봐야 할것같다...
728x90