문제 링크입니다: https://www.acmicpc.net/problem/14405
14405번: 피카츄
피카츄는 "pi", "ka", "chu"를 발음할 수 있다. 따라서, 피카츄는 이 세 음절을 합친 단어만 발음할 수 있다. 예를 들면, "pikapi"와 "pikachu"가 있다. 문자열 S가 주어졌을 때, 피카츄가 발음할 수 있는 문
www.acmicpc.net
단순 재귀함수로 쉽게 풀 수 있는 문제였습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
string s; | |
bool canMake = false; | |
void func(int idx) | |
{ | |
if (idx == s.length()) | |
{ | |
canMake = true; | |
return; | |
} | |
if (s.substr(idx, 2) == "pi") | |
{ | |
func(idx + 2); | |
} | |
if (s.substr(idx, 2) == "ka") | |
{ | |
func(idx + 2); | |
} | |
if (s.substr(idx, 3) == "chu") | |
{ | |
func(idx + 3); | |
} | |
} | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
cin >> s; | |
func(0); | |
cout << (canMake ? "YES\n" : "NO\n"); | |
return 0; | |
} |

개발환경:Visual Studio 2022
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 15353번 큰 수 A+B (2) (0) | 2024.03.31 |
---|---|
백준 13244번 Tree (0) | 2024.03.31 |
백준 14391번 종이 조각 (0) | 2024.03.31 |
백준 1285번 동전 뒤집기 (0) | 2024.03.30 |
백준 19942번 다이어트 (1) | 2024.03.30 |