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
- 일시정지
- Scrooling
- joystick
- LayerMark
- Transform
- rigidbody
- raycasting
- 오브젝트 풀링
- Object Pooling
- rotation
- 프리팹
- 스크롤링
- Parallax
- Hp바
- Object Poling
- 플레이어 이동
- raycast
- CSharp #자료구조
- 플레이어 방향전환
- Unity
- Blend Type
- Animation State Machine
- Ainimation Blending
- 유니티
- apk
- Vector3
- 패럴렉스
- Prefabs
- 2D슈팅게임
- Hpbar
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.2 마법의 엘리베이터 본문
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/148653
1. 정답코드 및 핵심 아이디어, 유의사항
- 5보다 작은 수 ↓ , 5보다 큰 수 ↑
- 5일 때는 다음 수에 영향을 받으므로, 따로 처리
using System;
using System.Collections.Generic;
public class Solution
{
public int solution(int storey)
{
int answer = 0;
List<int> list = new List<int>();
// 리스트에 역순으로 담기
while (storey != 0)
{
list.Add(storey % 10);
storey /= 10;
}
for (int i = 0; i < list.Count; i++)
{
if (list[i] >= 10)
{
if (i + 1 < list.Count)
list[i + 1]++;
else
answer++;
}
else if (list[i] < 5)
{
answer += list[i];
}
else if (list[i] > 5)
{
answer += 10 - list[i];
if (i + 1 < list.Count)
list[i + 1]++;
else
answer++;
}
else if (list[i] == 5)
{
answer += list[i];
if (i + 1 < list.Count && list[i + 1] >= 5)
list[i + 1]++;
}
else
return -1;
}
return answer;
}
}
728x90
'Programmers - C# > CodingTest Lv.2' 카테고리의 다른 글
[프로그래머스 C#] Lv.2 k진수에서 소수 개수 구하기 (0) | 2023.08.25 |
---|---|
[프로그래머스 C#] Lv.2 호텔 대실 (0) | 2023.08.23 |
[프로그래머스 C#] Lv.2 소수 찾기 (1) | 2023.08.23 |
[프로그래머스 C#] Lv.2 스킬트리 (0) | 2023.08.23 |
[프로그래머스 C#] Lv.2 주식가격 (0) | 2023.08.23 |