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 |
Tags
- 누적 합
- 다익스트라
- DFS
- 브루트포스
- BFS
- 유니티
- 그래프
- 스택
- 투 포인터
- 백트래킹
- 유니온 파인드
- 시뮬레이션
- 구현
- XR Interaction Toolkit
- 문자열
- 다이나믹 프로그래밍
- 수학
- VR
- 그리디 알고리즘
- 자료구조
- Team Fortress 2
- 트리
- 우선순위 큐
- 재귀
- 정렬
- 알고리즘
- c++
- ue5
- Unreal Engine 5
- 백준
Archives
- Today
- Total
1일1알
백준 12933번 오리 C++ 본문
https://www.acmicpc.net/problem/12933
12933번: 오리
첫째 줄에 영선이가 녹음한 소리가 주어진다. 소리의 길이는 5보다 크거나 같고, 2500보다 작거나 같은 자연수이고, 'q','u','a','c','k'로만 이루어져 있다.
www.acmicpc.net
방문 체크를 하면서 계속 반복하면서 올바른 울음소리를 내는 사이클을 얼마나 반복하는지 세면 된다.
우는것을 시작도 안하는 경우, 울다 마는 경우 예외처리를 해줘야한다.
#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 |