코딩 테스트 맨텀 2023. 4. 30. 13:40
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/150368 나의 풀이 public class User { public int ratio; public int over; } public class Emoticon { public int originPrice; public int saleRatio; // 10, 20, 30, 40 public int GetSalePrice() => originPrice * (100 - saleRatio) / 100; } public int[] solution(int[,] users, int[] emoticons) { User[] arr = Enumerable.Range(0, use..
코딩 테스트 맨텀 2023. 4. 29. 16:13
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/169199 나의 풀이 public int solution(string[] board) { (int y, int x) target = (-1, -1); var open = new Queue(); var dist = new int[board.Length, board[0].Length]; // 초기 세팅 for(int y = 0; y < board.Length; ++y) { for(int x = 0; x < board[0].Length; ++x) { if(board[y][x] == 'D') dist[y, x] = -1; else if(board[y][x] == 'R')..
C# Study/C# 기초 맨텀 2023. 4. 25. 12:58
Enumerable.SequenceEqual 배열, 리스트 등 컬렉션의 요소들이 완전히 동일한 멤버과 순서를 가지고 있는지 체크하는데 사용한다. Enumerable.SequenceEqual (this System.Collections.Generic.IEnumerable first, System.Collections.Generic.IEnumerable second); 사용 예 List arr1 = new List { obj1, obj2 }; List arr2 = new List { obj1, obj2 }; bool equal1 = arr1.SequenceEqual(arr2); // 확장 메서드 bool equal2 = Enumerable.SequenceEqual(arr1, arr2); // 정적 메서드
코딩 테스트 맨텀 2023. 4. 19. 22:53
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/142085# 1차 시도 public int solution(int n, int k, int[] enemy) { int size = enemy.Length; if(k >= size) return size; var used = new int[k]; // 무적권을 사용한 스테이지의 인덱스 int minValue = int.MaxValue; int minIndex = 0; // 최소 값이 들어있는 used 배열 내에서의 인덱스 // 미리 k개를 사용한다. for(int i = 0; i enemy[i])..
코딩 테스트 맨텀 2023. 4. 16. 19:38
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/150369 나의 코드 public long solution(int cap, int n, int[] deliveries, int[] pickups) { long answer = 0; int deliverIndex = Array.FindLastIndex(deliveries, (f) => f != 0); // 가장 먼 집부터 배달가야 함. int pickupIndex = Array.FindLastIndex(pickups, (f) => f != 0); // 가장 먼 집부터 회수해야 함. while(deliverIndex >= 0 || pickupIndex >= 0) { ..
코딩 테스트 맨텀 2023. 4. 15. 13:59
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/176962 나의 풀이 public class Test { public string name; public int start; public int remain; public Test(string name, string timeStr, string playTimeStr) { this.name = name; string[] splited = timeStr.Split(':'); start = int.Parse(splited[0]) * 60 + int.Parse(splited[1]); remain = int.Parse(playTimeStr); } } public strin..