분류 전체보기
-
최대공약수와 최소공배수Programmers 2023. 3. 26. 01:08
문제 설명 두 수를 입력받아 두 수의 최대공약수와 최소공배수를 반환하는 함수, solution을 완성해 보세요. 배열의 맨 앞에 최대공약수, 그다음 최소공배수를 넣어 반환하면 됩니다. 예를 들어 두 수 3, 12의 최대공약수는 3, 최소공배수는 12이므로 solution(3, 12)는 [3, 12]를 반환해야 합니다. 제한 사항 두 수는 1이상 1000000이하의 자연수입니다. 입출력 예 n m return 3 12 [3, 12] 2 5 [1, 10] 나의 풀이 def solution(n, m): a = n b = m if n>m: # 반드시 큰 값이 m, 작은 값이 n이 되게끔 만들어준다. n,m = m,n while m%n: # m을 n으로 나눈 나머지가 0이 아닌 동안에 r = m%n m = n n..
-
Socket Programming에 대해Network 2023. 3. 24. 21:37
- Socket : 사전적으로 구멍, 연결, 콘센트를 의미 - 전기 공급 인프라 환경에 연결할 수 있게 만들어진 연결부 - 프로그램이 네트워크에서 데이터를 송수신할 수 있도록 네트워크 환경에 연결할 수 있게 만들어진 연결부 소켓은 정해전 통신 프로토콜에 맞게 만들어져야 하며, 보통 OSI 7계층 중 4계층 Transport 계층 상에서 동작하는 소켓을 사용한다. 이때 소켓을 "TCP/IP 소켓" 또는 "UDP 소켓"이라고 부른다. 소켓으로 네트워크 통신 기능을 구현하기 위해서는 소켓을 만들고, 소켓을 통해 데이터를 주고 받는 절차에 대한 이해가 필요하며, 운영체제 및 프로그래밍 언어에 종속적으로 제공하는 소켓 API 사용법을 숙지해야 한다. 또한 소켓 프로그래밍 중 케이블 분리로 인한 네트워크 단절, 트..
-
행렬의 덧셈Programmers 2023. 3. 23. 21:40
문제 설명 행렬의 덧셈은 행과 열의 크기가 같은 두 행렬의 같은 행, 같은 열의 값을 서로 더한 결과가 됩니다. 2개의 행렬 arr1과 arr2를 입력받아, 행렬 덧셈의 결과를 반환하는 함수, solution을 완성해주세요. 제한 조건 행렬 arr1, arr2의 행과 열의 길이는 500을 넘지 않습니다. 입출력 예 arr1 arr2 return [[1,2],[2,3]] [[3,4],[5,6]] [[4,6],[7,9]] [[1],[2]] [[3],[4]] [[4],[6]] 나의 풀이 def solution(arr1, arr2): answer = [] for i in range(len(arr1)): answer.append([arr1[i][j] + arr2[i][j] for j in range(len(arr..
-
LS Routing, DV RoutingNetwork 2023. 3. 23. 14:43
네트워크 강의를 듣던 중에, 네트워크 계층에 대한 내용을 다루던 중 라우팅 개념에 대한 설명이 스킵된 것 같아 자세히 알아보기 위해 라우팅 프로토콜을 정리해보았다. Routing - 정적 라우팅(Static Routing) : 패킷 전송이 이루어지기 전 경로 정보를 라우터를 미리 저장하여 중개 - 단점으로는 경로 정보의 갱신이 어려워 네트워크 변화와 혼잡도에 대한 대처가 어려움 - 동적 라우팅(Dynamic Routing) : 라우터의 경로 정보가 네트워크 상황에 따라 적절히 조절되는 것 - 단점으로는 경로 정보의 수집과 관리로 인해 성능 저하 발생 - RIP, IGRP, OSPF, EIGRP 등이 Dynamic Routing에 속함 링크 상태(LS) 라우팅 알고리즘 cost Hop Count, Band..
-
나누어 떨어지는 숫자배열Programmers 2023. 3. 19. 18:01
문제 설명 array의 각 element 중 divisor로 나누어 떨어지는 값을 오름차순으로 정렬한 배열을 반환하는 함수, solution을 작성해주세요.divisor로 나누어 떨어지는 element가 하나도 없다면 배열에 -1을 담아 반환하세요. 제한사항 arr은 자연수를 담은 배열입니다. 정수 i, j에 대해 i ≠ j 이면 arr[i] ≠ arr[j] 입니다. divisor는 자연수입니다. array는 길이 1 이상인 배열입니다. 입출력 예 arr divisor return [5, 9, 7, 10] 5 [5, 10] [2, 36, 1, 3] 1 [1, 2, 3, 36] [3,2,6] 10 [-1] 입출력 예 설명 입출력 예#1arr의 원소 중 5로 나누어 떨어지는 원소는 5와 10입니다. 따라서 ..
-
실패율Programmers 2023. 3. 19. 17:51
실패율 슈퍼 게임 개발자 오렐리는 큰 고민에 빠졌다. 그녀가 만든 프랜즈 오천성이 대성공을 거뒀지만, 요즘 신규 사용자의 수가 급감한 것이다. 원인은 신규 사용자와 기존 사용자 사이에 스테이지 차이가 너무 큰 것이 문제였다. 이 문제를 어떻게 할까 고민 한 그녀는 동적으로 게임 시간을 늘려서 난이도를 조절하기로 했다. 역시 슈퍼 개발자라 대부분의 로직은 쉽게 구현했지만, 실패율을 구하는 부분에서 위기에 빠지고 말았다. 오렐리를 위해 실패율을 구하는 코드를 완성하라. 실패율은 다음과 같이 정의한다. 스테이지에 도달했으나 아직 클리어하지 못한 플레이어의 수 / 스테이지에 도달한 플레이어 수 전체 스테이지의 개수 N, 게임을 이용하는 사용자가 현재 멈춰있는 스테이지의 번호가 담긴 배열 stages가 매개변수로..
-
제일 작은 수 제거하기Programmers 2023. 3. 19. 16:09
문제 설명 정수를 저장한 배열, arr 에서 가장 작은 수를 제거한 배열을 리턴하는 함수, solution을 완성해주세요. 단, 리턴하려는 배열이 빈 배열인 경우엔 배열에 -1을 채워 리턴하세요. 예를들어 arr이 [4,3,2,1]인 경우는 [4,3,2]를 리턴 하고, [10]면 [-1]을 리턴 합니다. 제한 조건 arr은 길이 1 이상인 배열입니다. 인덱스 i, j에 대해 i ≠ j이면 arr[i] ≠ arr[j] 입니다. 입출력 예 arr return [4,3,2,1] [4,3,2] [10] [-1] 나의 풀이 def solution(arr): if len(arr) == 1: return [-1] else: arr.remove(min(arr)) return arr 다른 사람의 풀이 def rm_sma..
-
소수 찾기Programmers 2023. 3. 19. 16:09
문제 설명 1부터 입력받은 숫자 n 사이에 있는 소수의 개수를 반환하는 함수, solution을 만들어 보세요. 소수는 1과 자기 자신으로만 나누어지는 수를 의미합니다.(1은 소수가 아닙니다.) 제한 조건 n은 2이상 1000000이하의 자연수입니다. 입출력 예 n result 10 4 5 3 입출력 예 설명 입출력 예 #11부터 10 사이의 소수는 [2,3,5,7] 4개가 존재하므로 4를 반환 입출력 예 #21부터 5 사이의 소수는 [2,3,5] 3개가 존재하므로 3를 반환 나의 풀이 def solution(n): primes = [True] * (n+1) primes[0] = primes[1] = False for i in range(2, int(n**0.5)+1): if primes[i]: for ..