※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 5013번 문제인 Death Knight Hero이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/5013
5013번: Death Knight Hero
Output the number of battles our hero won, assuming he won each battle where he did not Chains of Ice immediately followed by Death Grip.
www.acmicpc.net
주어지는 N개의 문자열 중, "CD"라는 부분문자열이 존재하지 않는 문자열의 개수를 세는 문제이다.
각 문자열마다 "CD"와 일치하는 부분문자열이 존재하는지를 직접 탐색해 문제를 해결하자.
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
using namespace std;
int ans = 0;
void solve() {
int chk = 1;
string s; cin >> s;
char old = 'X';
for (auto& l : s) {
if (old == 'C' && l == 'D') chk = 0;
old = l;
}
if (chk) ans++;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T; cin >> T;
while (T--) {
solve();
}
cout << ans;
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 25199 // C++] 도박사 곰곰 (0) | 2022.05.15 |
---|---|
[BOJ 25194 // C++] 결전의 금요일 (0) | 2022.05.15 |
[BOJ 1774 // C++] 우주신과의 교감 (0) | 2022.05.15 |
[BOJ 14013 // C++] Unit Conversion (0) | 2022.05.15 |
[BOJ 14935 // C++] FA (0) | 2022.05.15 |