๐๏ธ ๊ฒช์ ๋ฌธ์
๐ ํด๊ฒฐ ๋ฐฉ๋ฒ
- substr๋ก ํญ๋ฐ ์ด์ ๊บผ + ํญ๋ฐ ์ดํ๊บผ ๋ฅผ ์๋ผ์ ๋ํ๋๋ ์๊ฐ ์ด๊ณผ๊ฐ ๋ฐ์ํ๋ค.
- result๋ฐฐ์ด์ ํ๋์ฉ ์ถ๊ฐํ๋ฉฐ ํญ๋ฐ ์ ํญ๋ฐ ๋ฌธ์์ด ๊ธธ์ด๋งํผ๋ง ์ง์ฐ๋๋ก ํ์ฌ ์๊ฐ ์ด๊ณผ๋ฅผ ํด๊ฒฐํ๋ค.
๐ ์ฝ๋
#include <iostream>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
string str, boom;
cin >> str >> boom;
string result = "";
int boomLen = boom.length();
for (char ch : str) {
result += ch;
if (result.length() >= boomLen) {
if (result.substr(result.length() - boomLen) == boom) {
result.erase(result.end() - boomLen, result.end());
}
}
}
cout << (result.empty() ? "FRULA" : result) << '\n';
return 0;
}