ALGORITHM/PYTHON

백준 BAEKJOON 30403번 무지개 만들기 [PYTHON/파이썬]

칼코
반응형

 

 

 

 

 

백준 BAEKJOON 30403번 무지개 만들기 [PYTHON/파이썬]


<문제 출처> (BRONZE Ⅱ)

https://www.acmicpc.net/problem/30403

 

30403번: 무지개 만들기

무지개 문자열은 R(빨간색), O(주황색), Y(노란색), G(초록색), B(파란색), I(남색), V(보라색) 순으로 이루어진 문자열이며, 대소문자를 구분하지 않는다. 임스는 춘배에게 영어 대소문자로 이루어진

www.acmicpc.net

 

 

 

 

 

 

 

<풀이>

소문자, 대문자로 이루어진 리스트와

확인할 수 있는 Boolean 변수를 만들어주고 시작했다.

for문을 돌면서 무지개 색의 단어가 없으면 False로 바꾼 뒤

마지막 if문을 통해 정답을 출력했다.

 

 

 

 

 

 

 

 

<코드>

lowerRainbow = ["r", "o", "y", "g", "b", "i", "v"]
upperRainbow = ["R", "O", "Y", "G", "B", "I", "V"]

N = int(input())
word = input()
lowerCheck = upperCheck = True

for i in range(7):
    if lowerRainbow[i] not in word:
        lowerCheck = False
    if upperRainbow[i] not in word:
        upperCheck = False

if lowerCheck and upperCheck:
    print("YeS")
elif lowerCheck:
    print("yes")
elif upperCheck:
    print("YES")
else:
    print("NO!")

 

 

 

 

 

 

 

 

 

반응형