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 |
Tags
- Unreal Engine 5
- 정렬
- Team Fortress 2
- 자료구조
- 수학
- DFS
- BFS
- 다이나믹 프로그래밍
- 투 포인터
- 다익스트라
- 누적 합
- 유니온 파인드
- 재귀
- 우선순위 큐
- 스택
- 백준
- 그리디 알고리즘
- 백트래킹
- VR
- 그래프
- 트리
- 브루트포스
- ue5
- 유니티
- 시뮬레이션
- 구현
- 알고리즘
- XR Interaction Toolkit
- c++
- 문자열
Archives
- Today
- Total
1일1알
백준 12933번 오리 C++ 본문
https://www.acmicpc.net/problem/12933
방문 체크를 하면서 계속 반복하면서 올바른 울음소리를 내는 사이클을 얼마나 반복하는지 세면 된다.
우는것을 시작도 안하는 경우, 울다 마는 경우 예외처리를 해줘야한다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
string str;
char c[5] = { 'q','u','a','c','k' };
vector<bool> visited;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> str;
if (str.length() % 5 != 0) {
cout << -1;
}
else {
visited = vector<bool>(str.length(), false);
int ans = 0;
int cnt = 0;
while (true) {
int targetIdx = 0;
int tmpCnt = 0;
for (int i = 0; i < str.length(); i++) {
if (visited[i]) continue;
if (str[i] != c[targetIdx]) continue;
targetIdx = (targetIdx + 1) % 5;
visited[i] = true;
tmpCnt++;
}
if (tmpCnt == 0 || targetIdx != 0) {
cout << -1;
return 0;
}
cnt += tmpCnt;
ans++;
if (cnt == str.length()) break;
}
cout << ans;
}
}
'알고리즘' 카테고리의 다른 글
백준 17085번 십자가 2개 놓기 C++ (1) | 2023.05.14 |
---|---|
백준 11536번 줄 세우기 C++ (0) | 2023.05.13 |
백준 15671번 오델로 C++ (0) | 2023.05.11 |
백준 25206번 너의 평점은 C++ (0) | 2023.05.09 |
백준 2331번 반복수열 C++ (0) | 2023.05.08 |