250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Unity
- 2D슈팅게임
- raycasting
- CSharp #자료구조
- 유니티
- 일시정지
- Prefabs
- joystick
- Vector3
- 프리팹
- Parallax
- rotation
- Ainimation Blending
- LayerMark
- Object Pooling
- 플레이어 방향전환
- Object Poling
- Transform
- 패럴렉스
- 오브젝트 풀링
- Hpbar
- Hp바
- Scrooling
- 스크롤링
- Blend Type
- Animation State Machine
- apk
- rigidbody
- raycast
- 플레이어 이동
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.1 공원 산책 본문
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/172928
1. 정답코드 및 핵심 아이디어, 유의사항
- currPosition이라는 현재 위치를 가진 int형 배열을 선언
주석 참조
using System;
public class Solution
{
public int[] solution(string[] park, string[] routes)
{
int[] currPosition = new int[2] { -1, -1 };
// 출발 위치 찾기
for (int i = 0; i < park.Length; i++)
{
for (int j = 0; j < park[i].Length; j++)
{
if (park[i][j] == 'S')
{
currPosition[0] = i;
currPosition[1] = j;
break;
}
}
if (currPosition[0] != -1 && currPosition[1] != -1)
break;
}
// 길 찾기
for (int i = 0; i < routes.Length; i++)
{
int moveToY, moveToX;
moveToY = currPosition[0];
moveToX = currPosition[1];
bool isMove = true;
for (int j = 0; j < (int)routes[i][2] - (int)'0'; ++j)
{
if (routes[i][0] == 'N') moveToY--;
else if (routes[i][0] == 'S') moveToY++;
else if (routes[i][0] == 'E') moveToX++;
else if (routes[i][0] == 'W') moveToX--;
if (moveToY < 0 || moveToY >= park.Length ||
moveToX < 0 || moveToX >= park[0].Length ||
park[moveToY][moveToX] == 'X')
{
isMove = false;
break;
}
}
if (isMove)
currPosition = new int[2] { moveToY, moveToX };
}
return currPosition;
}
}
728x90
'Programmers - C# > CodingTest Lv.1' 카테고리의 다른 글
[프로그래머스 C#] Lv.1 대충 만든 자판 (0) | 2023.08.30 |
---|---|
[프로그래머스 C#] Lv.1 둘만의 암호 (0) | 2023.08.23 |
[프로그래머스 C#] Lv.1 성격 유형 검사하기 (0) | 2023.08.22 |
[프로그래머스 C#] Lv.1 달리기 경주 (0) | 2023.08.20 |
[프로그래머스 C#] Lv.1 숫자 짝꿍 (0) | 2023.08.18 |