관리 메뉴

솜씨좋은장씨

[BaekJoon] 6778번 : Which Alien? (Python) 본문

Programming/코딩 1일 1문제

[BaekJoon] 6778번 : Which Alien? (Python)

솜씨좋은장씨 2022. 8. 23. 09:15
728x90
반응형

코딩 1일 1문제! 오늘의 문제는 백준의 Which Alien? 입니다.

 

6778번: Which Alien?

Canada Cosmos Control has received a report of another incident. They believe that an alien has illegally entered our space. A person who witnessed the appearance of the alien has come forward to describe the alien’s appearance. It is your role within th

www.acmicpc.net

👨🏻‍💻 문제 풀이

단순하게 문제에 주어진 대로 조건문을 만들고 그 조건문을 활용하여

현재 도착한 외계인이 어떤 외계인인지 구분하는 문제입니다.

  • TroyMartian, who has at least 3 antenna and at most 4 eyes;
def is_TroyMartian(antenna, eyes):
    is_troymartian = False
    
    if antenna >= 3 and eyes <= 4:
        is_troymartian = True
        
    return is_troymartian
  • VladSaturnian, who has at most 6 antenna and at least 2 eyes;
def is_VladSaturnian(antenna, eyes):
    is_vladsaturnian = False
    
    if antenna <= 6 and eyes >= 2:
        is_vladsaturnian = True
        
    return is_vladsaturnian
  • GraemeMercurian, who has at most 2 antenna and at most 3 eyes.
def is_GraemeMercurian(antenna, eyes):
    is_greamemercurian = False
    
    if antenna <= 2 and eyes <= 3:
        is_greamemercurian = True
        
    return is_greamemercurian

각 외계인별 조건을 구분하는 함수를 만들어 주었습니다.

def which_alien(antenna, eyes):
    answer = []
    
    if is_TroyMartian(antenna, eyes):
        answer.append("TroyMartian")
    
    if is_VladSaturnian(antenna, eyes):
        answer.append("VladSaturnian") 
    
    if is_GraemeMercurian(antenna, eyes):
        answer.append("GraemeMercurian")
        
    return answer

해당 함수를 활용하여 각 함수에서 해당 외계인이라고 판별되었을 경우

해당 외계인의 이름을 정답 리스트에 추가해주었습니다.

def print_answer(answer):
    for ans in answer:
        print(ans)

그렇게 모아진 정답을 출력하면 끝!

👨🏻‍💻 코드 ( Solution )

def is_TroyMartian(antenna, eyes):
    is_troymartian = False
    
    if antenna >= 3 and eyes <= 4:
        is_troymartian = True
        
    return is_troymartian


def is_VladSaturnian(antenna, eyes):
    is_vladsaturnian = False
    
    if antenna <= 6 and eyes >= 2:
        is_vladsaturnian = True
        
    return is_vladsaturnian


def is_GraemeMercurian(antenna, eyes):
    is_greamemercurian = False
    
    if antenna <= 2 and eyes <= 3:
        is_greamemercurian = True
        
    return is_greamemercurian


def which_alien(antenna, eyes):
    answer = []
    
    if is_TroyMartian(antenna, eyes):
        answer.append("TroyMartian")
    
    if is_VladSaturnian(antenna, eyes):
        answer.append("VladSaturnian") 
    
    if is_GraemeMercurian(antenna, eyes):
        answer.append("GraemeMercurian")
        
    return answer


def print_answer(answer):
    for ans in answer:
        print(ans)


if __name__ == "__main__":
    antenna = int(input())
    eyes = int(input())
    
    answer = which_alien(antenna=antenna, eyes=eyes)
    
    print_answer(answer=answer)
 

GitHub - SOMJANG/CODINGTEST_PRACTICE: 1일 1문제 since 2020.02.07

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

Comments