Coding Test/BaekJoon_C++

백준 9935 <문자열 폭발> C++

JunOnJuly 2024. 3. 13. 16:50
728x90

https://www.acmicpc.net/problem/9935

 

9935번: 문자열 폭발

첫째 줄에 문자열이 주어진다. 문자열의 길이는 1보다 크거나 같고, 1,000,000보다 작거나 같다. 둘째 줄에 폭발 문자열이 주어진다. 길이는 1보다 크거나 같고, 36보다 작거나 같다. 두 문자열은 모

www.acmicpc.net


 

 

백준 9936 <문자열 폭발> Python

https://www.acmicpc.net/problem/9935 9935번: 문자열 폭발 첫째 줄에 문자열이 주어진다. 문자열의 길이는 1보다 크거나 같고, 1,000,000보다 작거나 같다. 둘째 줄에 폭발 문자열이 주어진다. 길이는 1보다 크

dev-diary-0717.tistory.com

 

전에 작성한 파이썬 코드를 C++ 코드로 변환했습니다.


#include <iostream>
//
#include <string>
//
#include <algorithm>

using namespace std;

int main(void)
{
    string word;
    cin >> word;

    string exp;
    cin >> exp;

    string stk;
    int idx{};
    while (idx<word.size())
    {
        stk += word[idx];
        if (stk.size() >= exp.size() and stk.back() == exp.back())
        {
            if (stk.substr(stk.length() - exp.length(), exp.length()) == exp)
            {
                stk.erase(stk.length() - exp.length(), exp.length());
            }
        }
        idx += 1;
    }

    if (stk.size() > 0) cout << stk;
    else cout << "FRULA";
}  

 

728x90