백준 8826번: Spacer #Python

ColorlessDia·2025년 10월 20일

algorithm/baekjoon

목록 보기
701/807
import sys

input = sys.stdin.readline

Z = int(input())

for _ in range(Z):
    N = int(input())
    move_list = input().rstrip()

    x, y = 0, 0

    for move in move_list:
        
        if move == 'N':
            y += 1
        elif move == 'S':
            y -= 1
        elif move == 'E':
            x += 1
        elif move == 'W':
            x -= 1
    
    distance = abs(x) + abs(y)

    print(distance)

0개의 댓글