PS
BOJ 11008 : 복붙의 달인
lickelon
2025. 2. 10. 21:51
- 문제 링크 : boj.kr/11008
- 난이도 : S5
- 태그 : 문자열
코드
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define INF 0x7FFFFFFF
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int T;
cin >> T;
while(T--) {
string s, p;
cin >> s >> p;
while(s.find(p) != s.npos) {
int idx = s.find(p);
s.replace(idx, p.length(), "-");
}
cout << s.length() << "\n";
}
return 0;
}
풀이
s에서 더이상 p를 못 찾을 때까지 s에 존재하는 p를 임의의 한 자리 문자열("-")로 교체한다.
모두 교체하고 난 뒤 s의 길이가 답이 된다.
728x90