●문제
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 |
