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