Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 프로그래밍
- 빅데이터
- 프로그래머스
- Python
- 자바
- 모의 주식
- 풀스택프레임워크
- C++
- 개발
- 사물인터넷
- backend
- frontend
- Reflex
- 자바독학
- java정리
- 코테
- 코스닥
- SNS
- 자바정리
- 이웃한 칸
- 코딩독학
- java
- 코딩
- 개발자
- 프로그램
- 백준
- 개인프로젝트
- 주가예측
- 코딩테스트
- Project
Archives
- Today
- Total
Creative Code
이웃한 칸 본문
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int dh[4] = {0,1,-1,0}; // 세로로 이동할 방향
int dw[4] = {1,0,0,-1}; // 가로로 이동할 방향
int solution(vector<vector<string>> board, int h, int w) {
int answer = 0; // 이웃한 칸이 같은색깔인경우의 수
int n = board.size();
for (int i = 0; i < 4; i++) {
int h_check = h + dh[i]; // 체크할 칸
int w_check = w + dw[i];
if (h_check < 0 || h_check >= n || w_check < 0 || w_check >= n) continue; // 범위를 벗어날시 패스
else {
if (board[h][w] == board[h_check][w_check]) { // 색깔이 같으면 경우의 수 1추가
answer++;
}
}
}
return answer;
}
int main() {
cout << solution({ {"blue","red","orange","red"},{"red","red","blue","orange"},
{"blue","orange","red","red"},{"orange","orange","red","blue"} }, 1, 1) << endl;
cout << solution({ {"yellow","green","blue"},{"blue","green","yellow"},
{"yellow","blue","blue"} }, 0, 1) << endl;
}
https://school.programmers.co.kr/learn/courses/30/lessons/250125
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
'프로그래머스 코테 문제 > LEVEL 1' 카테고리의 다른 글
가장 많이 받은 선물 (0) | 2024.04.12 |
---|---|
데이터 분석 (0) | 2024.04.12 |
붕대 감기 (0) | 2024.04.12 |