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
- 트리
- Team Fortress 2
- c++
- 다익스트라
- DFS
- 유니온 파인드
- 정렬
- Unreal Engine 5
- 브루트포스
- XR Interaction Toolkit
- 문자열
- 다이나믹 프로그래밍
- 누적 합
- 백트래킹
- 알고리즘
- 스택
- VR
- 백준
- 구현
- BFS
- ue5
- 우선순위 큐
- 그리디 알고리즘
- 재귀
- 유니티
- 투 포인터
- 자료구조
- 그래프
- 시뮬레이션
- 수학
Archives
- Today
- Total
1일1알
백준 13022번 늑대와 올바른 단어 C++ 본문
https://www.acmicpc.net/problem/13022
13022번: 늑대와 올바른 단어
첫째 줄에 단어가 주어진다. 단어는 w, o, l, f로만 이루어져 있으며, 길이는 50을 넘지 않는다.
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;
const int WORDCOUNT = 4;
char cs[4] = { 'w','o','l','f' };
vector<int> cnts;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string str;
cin >> str;
int idx = 0;
int ans = 1;
bool newStart = true;
cnts = vector<int>(WORDCOUNT, 0);
for (int i = 0; i < str.length(); i++) {
if (idx == 0 && newStart) {
newStart = false;
set<int> s;
for (auto a : cnts) {
s.insert(a);
}
if (s.size() != 1) ans = 0;
cnts = vector<int>(WORDCOUNT, 0);
}
if (cs[idx] == str[i]) {
cnts[idx]++;
}
else {
ans = 0;
break;
}
if (i == str.length() - 1) break;
if (str[i + 1] != cs[idx]) {
idx = (idx + 1) % WORDCOUNT;
if (idx == 0) newStart = true;
}
}
set<int> s;
for (auto a : cnts) {
s.insert(a);
}
if (s.size() != 1) ans = 0;
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 16139번 인간-컴퓨터 상호작용 C++ (0) | 2022.12.02 |
---|---|
백준 17390번 이건 꼭 풀어야 해! C++ (0) | 2022.11.30 |
백준 22252번 정보 상인 호석 C++ (0) | 2022.11.27 |
백준 10703번 유성 C++ (0) | 2022.11.26 |
백준 13424번 비밀 모임 C++ (0) | 2022.11.25 |