문제) 백준 - 문자열 - 문자열 폭발
https://www.acmicpc.net/problem/9935
9935번: 문자열 폭발
첫째 줄에 문자열이 주어진다. 문자열의 길이는 1보다 크거나 같고, 1,000,000보다 작거나 같다. 둘째 줄에 폭발 문자열이 주어진다. 길이는 1보다 크거나 같고, 36보다 작거나 같다. 두 문자열은 모
www.acmicpc.net
ans에 문자열을 더하면서 폭발 문자열의 끝과 확인하여 만약 같을 경우 폭발 문자열 전체를 확인하여 같을 경우 pop 합니다.
C++ 소스코드)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define endl "\n" | |
#define ll long long | |
#define INF 987654321 | |
#define MAX 3001 | |
using namespace std; | |
typedef pair<int, int> p; | |
int main() | |
{ | |
ios::sync_with_stdio(0); | |
cin.tie(0); cout.tie(0); | |
string s, bomb; cin >> s >> bomb; | |
string ans = ""; | |
for(int i = 0; i < s.size(); ++i){ | |
int idx = bomb.size() - 1; | |
ans += s[i]; | |
if(ans.size() < bomb.size()) continue; | |
int cnt = 0; | |
if(bomb[idx] == ans[ans.size() - 1]){ | |
cnt = 1; | |
for(int j = idx - 1; j>= 0; --j){ | |
if(bomb[j] == ans[ans.size() - (bomb.size() - j)]){ | |
cnt++; | |
} | |
} | |
} | |
if(cnt == bomb.size()) | |
for(int j = 0; j < bomb.size(); ++j) | |
ans.pop_back(); | |
} | |
if(ans.size()) | |
cout << ans; | |
else | |
cout << "FRULA"; | |
return 0; | |
} |
반응형
'PS(Problem Solving) > 백준_BOJ' 카테고리의 다른 글
[백준] 13302번 - 리조트 (C++) 문제 및 풀이 (0) | 2022.03.18 |
---|---|
[백준] 2075번 - N번째 큰 수 (C++) 문제 및 풀이 (0) | 2022.03.17 |
[백준] 1613번 - 역사 (C++) 문제 및 풀이 (0) | 2022.03.16 |
[백준] 1963번 - 소수 경로 (C++) 문제 및 풀이 (0) | 2022.03.16 |
[백준] 1261번 - 알고스팟 (C++) 문제 및 풀이 (0) | 2022.03.14 |
댓글