inblog logo
|
sxias
    Programmers_CT

    [Programmers_CT] 13. 산책

    문정준's avatar
    문정준
    Feb 11, 2025
    [Programmers_CT] 13. 산책
    Contents
    1. 문제 설명 - 빈칸 채우기제한 사항2. 입출력 예시3. 코드 작성4. 테스트 실행5. 제출 후 채점
    💡
    프로그래머스 코딩 테스트 13. 산책

    1. 문제 설명 - 빈칸 채우기

    notion image

    제한 사항

    notion image

    2. 입출력 예시

    notion image

    3. 코드 작성

    class Solution { public int[] solution(String route) { int east = 0; int north = 0; int[] answer = new int [2]; for(int i=0; i<route.length(); i++){ switch(route.charAt(i)){ case 'N': north++; break; case 'S': north--; break; case 'E': east++; break; case 'W': east--; break; } } answer[0] = east; answer[1] = north; return answer; } }
    • 가로, 세로로 이동하는 변수는 east, north밖에 없음
      • N = north++, S = north- - (남쪽은 북쪽의 반대)
      • E = east++, W = east- - (서쪽은 동쪽의 반대)
     

    4. 테스트 실행

    notion image

    5. 제출 후 채점

    notion image
    Share article
    Contents
    1. 문제 설명 - 빈칸 채우기제한 사항2. 입출력 예시3. 코드 작성4. 테스트 실행5. 제출 후 채점

    Sxias ㆍ a32176740@gmail.com

    RSS·Powered by Inblog