코딩 테스트 맨텀 2023. 3. 25. 14:24
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/172928 나의 풀이 public int[] solution(string[] park, string[] routes) { int y = 0; int x = 0; // 시작지점 찾기 foreach(string p in park) { int index = p.IndexOf('S'); if(index != -1) { x = index; break; } ++y; } // 길찾기 foreach(string route in routes) { string[] splited = route.Split(); string dir = splited[0]; int repeat = Con..
코딩 테스트 맨텀 2023. 3. 24. 16:21
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/62048 나의 풀이 public long solution(int w, int h) { long answer = 0; int gcd = GCD(w, h); int width = w / gcd; int height = h / gcd; double slope = height / (double)width; for(int x = 0; x < width; ++x) { int curY = (int)Math.Floor(slope * x); int nextY = (int)Math.Ceiling(slope * (x + 1)); answer += (h - (nextY - curY))..
코딩 테스트 맨텀 2023. 3. 23. 17:17
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/81302 나의 풀이 public int[] solution(string[,] places) { int[] answer = new int[5]; for(int room = 0; room < places.GetLength(0); ++room) { char[,] matrix = new char[5, 5]; for(int k = 0; k < 5; ++k) { string str = places[room, k]; for(int s = 0; s < str.Length; ++s) matrix[k, s] = str[s]; } answer[room] = IsCollectSpace..
코딩 테스트 맨텀 2023. 3. 22. 23:13
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/86971 나의 풀이 public int solution(int n, int[,] wires) { int answer = int.MaxValue; for(int i = 0; i < wires.GetLength(0); ++i) { int a = wires[i, 0]; int b = wires[i, 1]; var setA = new HashSet(); setA.Add(a); var setB = new HashSet(); setB.Add(b); FindConnect(wires, setA, a, i); FindConnect(wires, setB, b, i); int dif..
코딩 테스트 맨텀 2023. 3. 21. 17:44
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/12978 나의 풀이 public int solution(int N, int[,] road, int K) { // 거리 초기화 int[,] map = new int[N, N]; for(int i = 0; i < N; ++i) { for(int k = 0; k < N; ++k) map[i, k] = int.MaxValue; } for(int i = 0; i < road.GetLength(0); ++i) { int a = road[i, 0] - 1; int b = road[i, 1] - 1; int dist = road[i, 2]; if(dist < map[a, b])..
코딩 테스트 맨텀 2023. 3. 20. 14:26
출처: 프로그래머스 코딩 테스트 연습 https://school.programmers.co.kr/learn/courses/30/lessons/77485 개인적으로 제일 싫어하는 유형의 문제. 문제만 길고 내용은 노가다에 가깝다. 나의 풀이 public int[] solution(int rows, int columns, int[,] queries) { int[] answer = new int[queries.GetLength(0)]; int[,] matrix = new int[rows, columns]; // 매트릭스 채우기 int count = 0; for(int y = 0; y < rows; ++y) { for(int x = 0; x < columns; ++x) matrix[y, x] = ++count;..