Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- vector
- 구현
- 오에스
- 알고리즘
- bfs
- 백준
- Operating System
- cs
- 컴공
- 너비우선탐색
- Computer science
- 자료구조
- DP
- Stack
- 오퍼레이팅시스템
- 코딩
- 문제풀이
- coding
- 브루트포스
- 컴공과
- OS
- 정석
- c++
- 컴퓨터공학과
- 정석학술정보관
- 그래프
- 코테
- 개발
- 스택
- 북리뷰
Archives
- Today
- Total
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