-
[프로그래머스] 알고리즘 기초 10문제 (Python)Algorithm 2022. 2. 11. 14:32
1) 직사각형 별찍기
https://programmers.co.kr/learn/courses/30/lessons/12969
a, b = map(int, input().strip().split(' ')); for i in range(b): for j in range(a): print("*", end="") print()
2) 짝수와 홀수
https://programmers.co.kr/learn/courses/30/lessons/12937
def solution(num): answer = '' if(num % 2 != 0): answer = "Odd" else: answer = "Even" return answer
3) 가운데 글자 가져오기
https://programmers.co.kr/learn/courses/30/lessons/12903
import math; def solution(s): answer = "" length = len(s) # s의 길이 idx = math.floor(length/2) # length를 2로 나눈 몫 if(length % 2 != 0): for i in range(length): answer = s[idx] else: for i in range(length): answer = s[idx-1] + s[idx] return answer
4) 두 정수 사이의 합
https://programmers.co.kr/learn/courses/30/lessons/12912
def solution(a, b): answer = 0 if( a < b): for i in range(a, b+1): answer += i else: for i in range(b, a+1): answer += i return answer
5) 문자열을 정수로 바꾸기
https://programmers.co.kr/learn/courses/30/lessons/12925?
def solution(s): answer = int(s) return answer
6) 없는 숫자 더하기
https://programmers.co.kr/learn/courses/30/lessons/86051
def solution(numbers): answer = 0; sum = 0; for i in range(10): sum += i for i in numbers: answer += i answer = sum - answer return answer
7) 음양 더하기
https://programmers.co.kr/learn/courses/30/lessons/76501
def solution(absolutes, signs): answer = 0 for i in range(len(absolutes)): if(signs[i] == True): answer += absolutes[i] else: answer -= absolutes[i] return answer
8) 평균 구하기
https://programmers.co.kr/learn/courses/30/lessons/12944
def solution(arr): answer = 0 for i in arr: answer += i return answer/len(arr)
9) 핸드폰 번호 가리기
https://programmers.co.kr/learn/courses/30/lessons/12948
def solution(phone_number): answer = "" length = len(phone_number) - 4 list = phone_number[length:] # phone_number의 뒤에 4자리 for i in range(0,length): answer += "*" answer += list return answer
10) 행렬의 덧셈
https://programmers.co.kr/learn/courses/30/lessons/12950
def solution(arr1, arr2): answer = [] for i in range(len(arr1)): sumArr = [] for j in range(len(arr1[i])): sumArr.append(arr1[i][j] + arr2[i][j]) answer.append(sumArr) return answer
'Algorithm' 카테고리의 다른 글
[프로그래머스] 알고리즘 난이도 중하 8문제 (Python) -3 (0) 2022.02.12 [프로그래머스] 알고리즘 기초 10문제 (Python) -2 (0) 2022.02.11 [백준 알고리즘] 10773번: 제로 (JavaScript) (0) 2022.02.09 [인프런 강의] JS 알고리즘 문제풀이(코딩테스트 대비) - 섹션3 (0) 2022.02.06 [인프런 강의] JS 알고리즘 문제풀이(코딩테스트 대비) - 섹션2 (0) 2022.02.03