프로그래머스(C++) - 방문 길이

2025. 10. 24. 19:20·C++ 프로그래머스/기타 문제

●문제

https://school.programmers.co.kr/learn/courses/30/lessons/49994

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

●입출력

 

#include <string>
#include <map>
#include <set>
using namespace std;

int solution(string dirs) 
{
    map<char, pair<int, int>>map;
    map['U'] = { 0, 1 };
    map['D'] = { 0, -1 };
    map['L'] = { -1, 0 };
    map['R'] = { 1, 0 };
    //출발지점, 도착지점
    set < pair<pair<int, int>, pair<int, int>>> s;
    pair<int, int> currentPos = make_pair(0, 0);

    for (char ch : dirs)
    {
        int nx = currentPos.first + map[ch].first;
        int ny = currentPos.second + map[ch].second;

        if (nx > 5 || ny > 5 || nx < -5 || ny < -5)
            continue;

        s.insert({ currentPos, {nx, ny} });
        s.insert({ {nx, ny}, currentPos });

        currentPos = { nx, ny };
    }
    return s.size() / 2;

}

 

레벨 : 2 

점수 : 2

'C++ 프로그래머스 > 기타 문제' 카테고리의 다른 글

프로그래머스(C++) - 롤케이크 자르기  (0) 2025.10.20
프로그래머스(C++) - 행렬의 곱셈  (0) 2025.10.20
프로그래머스(C++) - 예상 대진표  (0) 2025.10.12
프로그래머스(C++) - 영어 끝말잇기  (0) 2025.10.12
프로그래머스(C++) - 귤 고르기  (0) 2025.10.10
'C++ 프로그래머스/기타 문제' 카테고리의 다른 글
  • 프로그래머스(C++) - 롤케이크 자르기
  • 프로그래머스(C++) - 행렬의 곱셈
  • 프로그래머스(C++) - 예상 대진표
  • 프로그래머스(C++) - 영어 끝말잇기
lucodev
lucodev
커피와 노트북 그리고 개발
  • lucodev
    루코 개발테이블
    lucodev
  • 전체
    오늘
    어제
    • 분류 전체보기 (211) N
      • Unreal 프로젝트 다이어리 (108) N
        • 첫번째 프로젝트 (73)
        • 두번째 프로젝트 (35) N
      • Unreal 팁 (8)
      • Unreal 디버깅 (8)
      • C++ 프로그래머스 (52)
        • Stack,Queue (7)
        • Hash (4)
        • Heap (2)
        • Sort (5)
        • Exhaustive search (5)
        • Greedy (2)
        • BFS , DFS (7)
        • Graph (2)
        • Dynamic Programming (1)
        • C++ Math (2)
        • 기타 문제 (14)
      • C++ 백준 (4)
      • C++ 팁 (1)
      • 개인 코테 & 스타디 <비공개> (29)
        • 코드 개인보관함 (9)
        • 코딩테스트+@ (11)
        • 알고리즘 스타디 (6)
        • 알고리즘 스타디 과제 (3)
        • 비공개 (0)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • 링크

  • 공지사항

  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 태그

    언리얼 파쿠르
    언리얼 상호작용
    Unreal Parkour
    언리얼 ui
    언리얼 인벤토리
    언리얼 모션매칭
    unreal 모션매칭
    언리얼 motionmatching
    언리얼
    unreal 인벤토리
    unreal 파쿠르
    언리얼 시퀀스
    unreal 시퀀스
    언리얼 behaviortree
    언리얼 parkour
    언리얼 비헤이비어트리
    언리얼 컷씬
    언리얼 프로그래스바
    언리얼 behavior tree
    unreal inventory
  • hELLO· Designed By정상우.v4.10.3
lucodev
프로그래머스(C++) - 방문 길이
상단으로

티스토리툴바