CodingTest/Baekjoon

[baekjoon] 백준 14405번(파이썬): 피카츄

JunJangE 2022. 1. 17. 00:36

문제

 

14405번: 피카츄

피카츄는 "pi", "ka", "chu"를 발음할 수 있다. 따라서, 피카츄는 이 세 음절을 합친 단어만 발음할 수 있다. 예를 들면, "pikapi"와 "pikachu"가 있다. 문자열 S가 주어졌을 때, 피카츄가 발음할 수 있는 문

www.acmicpc.net

알고리즘

- .replace()를 통해 피카츄가 발음할 수 있는 단어를 띄어쓰기로 바꾼다.

- .strip()을 통해 띄어쓰기를 붙였을 때 길이가 0이면 피카츄가 발음할 수 있는 문자열인 것이다.

코드

import sys


word = str(sys.stdin.readline().rstrip("\n"))

# replace를 통해 "pi", "ka", "chu" 발음을 띄어쓰기로 바꾼다.
word = word.replace("pi", " ")
word = word.replace("ka", " ")
word = word.replace("chu", " ")

# .strip()을 통해 띄어쓰기를 붙였을 때 길이가 0이면 피카츄가 발음할 수 있는 문자열인 것이다.
if len(word.strip()) == 0:
    print("YES")
else:
    print("NO")

github

 

GitHub - junjange/CodingTest: 내가 푼 코딩 테스트 문제와 해결법

내가 푼 코딩 테스트 문제와 해결법. Contribute to junjange/CodingTest development by creating an account on GitHub.

github.com