BOJ - 2671 - 잠수함식별

Updated:

def Contact(index, state, N):
    if(state == -1):
        print("NOISE")
        return

    if(index == len(N) and (state == 0 or state == 5 or state == 6 or state == 7)):
        print("SUBMARINE")
        return

    if(index == len(N)):
        print("NOISE")
        return

    if state == 0:
        if(N[index] == '0'):
            Contact(index + 1, 1, N)
        else:
            Contact(index + 1, 2, N)
    elif state == 1:
        if (N[index] == '0'):
            Contact(index + 1, -1, N)
        else:
            Contact(index + 1, 5, N)
    elif state == 2:
        if (N[index] == '0'):
            Contact(index + 1, 3, N)
        else:
            Contact(index + 1, -1, N)
    elif state == 3:
        if (N[index] == '0'):
            Contact(index + 1, 4, N)
        else:
            Contact(index + 1, -1, N)
    elif state == 4:
        if (N[index] == '0'):
            Contact(index + 1, 4, N)
        else:
            Contact(index + 1, 6, N)
    elif state == 5:
        if (N[index] == '0'):
            Contact(index + 1, 1, N)
        else:
            Contact(index + 1, 2, N)
    elif state == 6:
        if (N[index] == '0'):
            Contact(index + 1, 1, N)
        else:
            Contact(index + 1, 7, N)
    elif state == 7:
        if (N[index] == '0'):
            Contact(index + 1, 8, N)
        else:
            Contact(index + 1, 7, N)

    elif state == 8:
        if (N[index] == '0'):
            Contact(index + 1, 4, N)
        else:
            Contact(index + 1, 0, N)

def solution():
    N = str(input())

    Contact(0, 0, N)

solution()

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

Categories:

Updated:

Leave a comment