기록하지 않았다면 잃어버릴 시간들
Home
  • 분류 전체보기 (184)
    • Lang (6)
      • c++ (2)
      • Java (2)
      • python (2)
    • 프레임워크 (18)
      • Spring (16)
      • JPA (2)
    • 알고리즘 (141)
      • 이론 (4)
      • 백준 (59)
      • Codility (13)
      • 프로그래머스 (65)
    • CS (4)
      • 운영체제 (0)
      • 자료구조 (0)
      • DB (4)
      • 네트워크 (0)
      • 보안 (0)
    • 기타 (7)
    • 프로젝트 (4)
      • 게시판 만들기로 배우는 Spring Data JP.. (4)
Home
  • 분류 전체보기 (184)
    • Lang (6)
      • c++ (2)
      • Java (2)
      • python (2)
    • 프레임워크 (18)
      • Spring (16)
      • JPA (2)
    • 알고리즘 (141)
      • 이론 (4)
      • 백준 (59)
      • Codility (13)
      • 프로그래머스 (65)
    • CS (4)
      • 운영체제 (0)
      • 자료구조 (0)
      • DB (4)
      • 네트워크 (0)
      • 보안 (0)
    • 기타 (7)
    • 프로젝트 (4)
      • 게시판 만들기로 배우는 Spring Data JP.. (4)
블로그 내 검색

기록하지 않았다면 잃어버릴 시간들

새로운 것을 배우는게 즐거운 개발자입니다.

  • 알고리즘/프로그래머스

    Programers 공원 산책/ C++

    2023. 3. 29.

    by. 내이름은 킹햄찌

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

     

    프로그래머스

    코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

    programmers.co.kr

    아이디어

    일반 구현문제임, 이동 경로를 한번에 이동하지 않고 한칸씩 이동하며 X가 있는지 확인을 잘하는 것이 뽀인트

     

    #include <string>
    #include <vector>
    
    using namespace std;
    
    class Point {
    public:
    	Point() {};
    	void move(int _y, int _x) {
    		y = _y;
    		x = _x;
    	}
    	int getY() {
    		return y;
    	}
    	int getX() {
    		return x;
    	}
    private:
    	int y = 0;
    	int x = 0;
    };
    
    int dy[4] = { -1,1,0,0 };
    int dx[4] = { 0,0,-1,1 };
    
    int dic2Idx(char c) {
    	if (c == 'N') return 0;
    	if (c == 'S') return 1;
    	if (c == 'W') return 2;
    	if (c == 'E') return 3;
    }
    
    vector<int> solution(vector<string> park, vector<string> routes) {
    	vector<int> answer;
    	Point cur;
    	for (int i = 0; i < park.size(); i++) {
    		for (int j = 0; j < park[i].size(); j++) {
    			if (park[i][j] == 'S') { cur.move(i, j); break; }
    		}
    	}
    	for (auto route : routes) {
    		bool impassable;
    		int a = route[2] - '0';
    		int y = cur.getY();
    		int x = cur.getX();
    		for (int i = 0; i < (route[2] - '0'); i++) {
    			impassable = true;
    			y += dy[dic2Idx(route[0])];
    			x += dx[dic2Idx(route[0])];
    			if (y >= park.size() || y < 0 || x >= park[y].size() || x < 0) break;
    			if (park[y][x] == 'X') break;
    			impassable = false;
    		}
    		if (impassable) continue;
    		cur.move(y, x);
    	}
    	answer.push_back(cur.getY());
    	answer.push_back(cur.getX());
    	return answer;
    }

    '알고리즘 > 프로그래머스' 카테고리의 다른 글

    Programers 과제 진행하기/ C++  (0) 2023.04.01
    Programers 추억 점수/ C++  (0) 2023.04.01
    Programers 광물 캐기/ C++  (0) 2023.03.29
    Programers 덧칠하기/ C++  (0) 2023.03.04
    Programers 바탕화면 정리/ C++  (0) 2023.03.04

    댓글

    관련글

    • Programers 과제 진행하기/ C++ 2023.04.01
    • Programers 추억 점수/ C++ 2023.04.01
    • Programers 광물 캐기/ C++ 2023.03.29
    • Programers 덧칠하기/ C++ 2023.03.04
    맨 위로
전체 글 보기
Tistory 로그인
Tistory 로그아웃
로그아웃 글쓰기 관리

Today

Total

Powered by ⓒ Kakao Corp.

Designed by Nana
블로그 이미지
내이름은 킹햄찌

티스토리툴바