SDJ( 수돈재 아님 ㅎ )

[C++] 10750 - Censoring 본문

알고리즘/Backjoon

[C++] 10750 - Censoring

ShinDongJun 2020. 1. 23. 13:00

문제 링크 : https://www.acmicpc.net/problem/10750

 

10750번: Censoring

Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they have plenty of material to read while waiting around in the barn during milking sessions. Unfortunately, the latest issue contains a rather inappropriate article

www.acmicpc.net

 

 

문자열 폭발과 거의 같은 문제다.

문자열 폭발처럼 스택을이용해서 풀었다.

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<bits/stdc++.h>
 
using namespace std;
 
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    string S;
    char stack[1000005];
    int stack_len = 0;
    char bomb[105];
 
    cin >> S;
    cin >> bomb;
 
    int bomb_len = strlen(bomb);
 
    for(int i = 0; i < S.size(); ++i)
    {
        stack[stack_len++= S[i];
 
        if(bomb[bomb_len-1== stack[stack_len-1])
        {
            if(!strncmp(stack + stack_len - bomb_len, bomb, bomb_len))
            {
                stack_len -= bomb_len;
            }
        }
    }
    stack[stack_len] = '\0';
    cout << stack << endl;
 
    return 0;
}
Comments