백준 1063 - 킹

태태·2023년 5월 18일
0

문제


알고리즘 분류)

  • 시뮬레이션
  • 구현

풀이

개 킹받는 문제


소스코드

python)

def function(num):
    if -1 < num < 8:
        return True
    return False
def function2(num1,num2):
    if -1<num1<8 and -1<num2<8:
        return True
    return False
def stone_move(num1,num2,num3,num4):
    if num1==num3 and num2==num4:
        return True
    return False
array = [[0 for col in range(8)] for row in range(8)]
j={'A':0,'B':1,'C':2,'D':3,'E':4,'F':5,'G':6,'H':7}
i={'8':0,'7':1,'6':2,'5':3,'4':4,'3':5,'2':6,'1':7}
king, stone, N = map(str,input().split())
king_i = i[king[1]]
king_j = j[king[0]]
stone_i = i[stone[1]]
stone_j = j[stone[0]]

for _ in range(int(N)):
    text = input()
    if text=='B':
        if function(king_i+1):
            if stone_move(king_i+1,king_j,stone_i,stone_j):
                if function(stone_i+1):
                    stone_i+=1
                else:
                    continue
            king_i+=1
        else:
            continue
    elif text=='L':
        if function(king_j-1):
            if stone_move(king_i,king_j-1,stone_i,stone_j):
                if function(stone_j-1):
                    stone_j-=1
                else:
                    continue
            king_j-=1
        else:
            continue
    elif text=='R':
        if function(king_j+1):
            if stone_move(king_i,king_j+1,stone_i,stone_j):
                if function(stone_j+1):
                    stone_j+=1
                else:
                    continue
            king_j+=1
        else:
            continue
    elif text=='T':
        if function(king_i-1):
            if stone_move(king_i-1,king_j,stone_i,stone_j):
                if function(stone_i-1):
                    stone_i-=1
                else:
                    continue
            king_i-=1
        else:
            continue
    elif text=='RT':
        if function2(king_i-1,king_j+1):
            if stone_move(king_i-1,king_j+1,stone_i,stone_j):
                if function2(stone_i-1,stone_j+1):
                    stone_i,stone_j = stone_i-1,stone_j+1
                else:
                    continue
            king_i,king_j = king_i-1,king_j+1    
        else:
            continue
    elif text=='LT':
        if function2(king_i-1,king_j-1):
            if stone_move(king_i-1,king_j-1,stone_i,stone_j):
                if function2(stone_i-1,stone_j-1):
                    stone_i,stone_j = stone_i-1,stone_j-1
                else:
                    continue
            king_i,king_j = king_i-1,king_j-1    
        else:
            continue
    elif text=='RB':
        if function2(king_i+1,king_j+1):
            if stone_move(king_i+1,king_j+1,stone_i,stone_j):
                if function2(stone_i+1,stone_j+1):
                    stone_i,stone_j = stone_i+1,stone_j+1
                else:
                    continue
            king_i,king_j = king_i+1,king_j+1    
        else:
            continue
    elif text=='LB':
        if function2(king_i+1,king_j-1):
            if stone_move(king_i+1,king_j-1,stone_i,stone_j):
                if function2(stone_i+1,stone_j-1):
                    stone_i,stone_j = stone_i+1,stone_j-1
                else:
                    continue
            king_i,king_j = king_i+1,king_j-1    
        else:
            continue
        
        
jkey=list(j.keys())
ikey=list(i.keys())
print('{0}{1}\n{2}{3}'.format(jkey[king_j],ikey[king_i],jkey[stone_j],ikey[stone_i]))

하..

profile
과정에서 재미를 느끼지 않는데 성공하는 일은 거의 없다

0개의 댓글