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 |
Tags
- 프로그래머스
- 코테
- Lv.3
- Unity
- 백준 17070번 c++
- 백준 1103번
- 백준 c++ 2870번
- 2468 c++
- 백준 17070번
- 17070번
- 유니티
- 백준
- Algorithm
- 백준 c++ 2468번
- C#
- Beakjoon
- 백준 2870번
- 플레이어 이동
- 2870번 수학숙제 c++
- 백준 1103번 게임
- 수학숙제
- 2870번 수학숙제
- 2870번
- 오브젝트 풀링
- 백준 1103번 c++
- c++
- dfs
- Lv2
- 2870번 c++
- 코딩테스트
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.2 마법의 엘리베이터 본문
https://school.programmers.co.kr/learn/courses/30/lessons/148653
1. 정답코드 및 핵심 아이디어, 유의사항
마법의 엘리베이터 문제
- 만약 자릿수가 증가된다면 다음 자리 값에 영향을 주므로 역순으로 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;
}
list.Add(0);
for(int i = 0; i < list.Count - 1; i++)
{
if(list[i] == 5 && list[i + 1] >= 5)
{
list[i + 1] += 1;
answer += 5;
}
else if(list[i] > 5)
{
list[i + 1] += 1;
answer += (10 - list[i]);
}
else // list[i] <= 5
{
answer += list[i];
}
}
return answer + list[list.Count - 1];
}
}
'CodingTest > Programmers Lv.2' 카테고리의 다른 글
[프로그래머스 C#] Lv.2 충돌위험 찾기 (PCCP 기출문제 3번) (0) | 2024.09.23 |
---|---|
[프로그래머스 C#] Lv.2 퍼즐게임 (PCCP 기출문제 2번) (1) | 2024.09.23 |
[프로그래머스 C#] Lv.2 디펜스 게임 (0) | 2024.05.22 |
[프로그래머스 C#] Lv.2 피로도 (0) | 2024.05.22 |
[프로그래머스 C#] Lv.2 과제 진행하기 (0) | 2024.05.22 |