Notice
Recent Posts
Recent Comments
Link
Little Jay
[C++] 백준 24524번 - 아름다운 문자열 본문
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
string s, t;
void solve(string &s, string &t) {
vector<queue<int>> v;
int ans = 0;
int pos = -1;
int idx = 0;
v.resize(26);
for (int i = 0; i < s.size(); i++) {
v[s[i] - 'a'].push(i);
}
while (true) {
int temp = t[idx] - 'a';
while (!v[temp].empty() && pos > v[temp].front()) {
v[temp].pop();
}
if (!v[temp].empty()) {
pos = v[temp].front();
v[temp].pop();
}
else break;
idx++;
if (idx == t.size()) {
pos = -1;
ans++;
idx = 0;
}
}
cout << ans << endl;
exit(0);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> s >> t;
solve(s, t);
return 0;
}'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 18352 - 특정 거리의 도시 찾기 (0) | 2022.07.16 |
|---|---|
| [C++] 백준 1717번 - 집합의 표현 (0) | 2022.07.11 |
| [C++] 백준 3187번 - 양치기 꿍 (0) | 2022.07.09 |
| [C++] 백준 2608번 - 로마 숫자 (0) | 2022.07.04 |
| [C++] 백준 1541번 - 잃어버린 괄호 (0) | 2022.07.04 |
Comments