목록Algorithm (2)
seonggoc
델타 탐색델타 탐색은 인접한 배열을 탐색하기 위해 사용된다.dx,dy 배열을 만들고, 현재 좌표를 돌 때 dx, dy를 순회 (인접 배열 순회)하면 된다.#include using namespace std;int dx[4] = {-1, 1, 0, 0}; // 위, 아래, 왼쪽, 오른쪽int dy[4] = {0, 0, -1, 1};int main() { int x = 2, y = 2; // 현재 위치 cout (" 프로그래머스 안전지대에서 8방향으로 탐색할 때 사용했다.#include #include #include using namespace std;// 상 하 좌 우 좌상 우상 좌하 우하int dx[8] = {0, 0, -1, 1, -1, 1, -1, 1};int dy[8] = {1, -1..
1. String을 나누는 방법string을 나누는 방법은 많이 있다. getline, istringstream을 사용해서 나누거나, 직접 순회를 해서 해당하는 값을 처리하는 방법 등 다양한 방법이 있지만, 편하게 그때 그때 처리할 수 있는 범용적인 함수를 만들어 보는 것이 좋은 것 같다.아래는 C++로 구현한 split이다.#include #include std::vector split(const std::string &str, const std::string &delimeter){ auto start = 0; auto end = str.find(delimeter); std::vector result; while (end != std::string::npos) { ..