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
- BFS
- XR Interaction Toolkit
- 다이나믹 프로그래밍
- 백트래킹
- 재귀
- 다익스트라
- 유니티
- 수학
- 문자열
- Team Fortress 2
- c++
- 그래프
- 구현
- 자료구조
- 시뮬레이션
- 브루트포스
- 알고리즘
- 투 포인터
- 유니온 파인드
- Unreal Engine 5
- 스택
- 백준
- 트리
- VR
- 그리디 알고리즘
- DFS
- 정렬
- 우선순위 큐
- ue5
- 누적 합
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 |