Simple_PS

  • Lv0 프로그래머스(Programmers)[Python][파이썬] 겹치는 선분의 길이
    """ 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/courses/30/lessons/120876 """ #풀이 과정 #점 개념 선 개념 정확히 생각 후 풀기! 핵심 생각 def solution(lines): result = 0 num = [] for a, b in lines: num.append(range(a, b + 1)) a = set(num[0]) b = set(num[1]) c = set(num[2]) x = a & b print("x", x) if not len(x) == 0: result += len(x) - 1 print("1", result) y = (b & c) # - (a & b & c) print("y", y) if not len(y) == 0: result += len(y) - 1 print("2", result) z = (a & c) # - (a & b & c) print("z", z) if not len(z) == 0: result += len(z) - 1 print(result) if not len(a & b & c) == 0: result -= 2 * (len(a & b & c) - 1) return result else: return result
  • Lv0 프로그래머스(Programmers)[Python][파이썬] 개미 군단
    """ 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/courses/30/lessons/120837 """ # 풀이 과정 def solution(hp): count=0 while True: for a in [5,3,1]: if hp>=a: count+=int(hp/a) hp=hp%a if hp==0: return count if hp==0: return 0
  • Lv0 프로그래머스(Programmers)[Python][파이썬] 간단한 식 계산하기
    """ 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/courses/30/lessons/181865 """ # 풀이 과정 def solution(binomial): return eval(binomial)
  • Lv0 프로그래머스(Programmers)[Python][파이썬] 간단한 논리 연산
    """ 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/courses/30/lessons/181917 """ # 내 풀이 def solution(x1, x2, x3, x4): if x1==False and x2==False: l=False else: l=True if x3==False and x4==False: m=False else: m=True return True if l==True and m==True else False
  • Lv0 프로그래머스(Programmers)[Python][파이썬] 각도기
    """ 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/courses/30/lessons/120829 """ # 풀이 과정 def solution(angle): if angle<90: return 1 elif angle==90: return 2 elif 90<angle<180: return 3 elif angle==180: return 4
  • Lv0 프로그래머스(Programmers)[Python][파이썬] 가장 큰 수 찾기
    """ 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/courses/30/lessons/120899 """ # 풀이 과정 def solution(array): answer = [] x = max(array) answer.append(x) y = array.index(max(array)) answer.append(y) return answer # 내 풀이 2 def solution(array): answer = [] x = max(array) answer.append(x) y = array.index(x) answer.append(y) return answer
  • Lv0 프로그래머스(Programmers)[Python][파이썬] 가위 바위 보
    """ 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/courses/30/lessons/120839 """ # 풀이 과정 def solution(rsp): a = list(rsp) result = [] for x in a: if x == "2": result.append("0") elif x == "0": result.append("5") elif x == "5": result.append("2") answer = "".join(result) return answer
  • Lv0 프로그래머스(Programmers)[Python][파이썬] 가까운 1로 찾기
    """ 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/courses/30/lessons/181898 """ # 풀이 과정 def solution(arr, idx): for x in range(idx,len(arr)): if arr[x]==1: return x return -1
  • Lv0 프로그래머스(Programmers)[Python][파이썬] 가까운 수
    """ 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/courses/30/lessons/120890 """ # 풀이 과정1 def solution(array, n): answer = 0 num = [] num_abs = [] for x in range(len(array)): a = abs(array[x] - n) if len(num) == 0: num.append(array[x]) num_abs.append(a) elif len(num) == 1: if num_abs[0] > a: num.pop() num.append(array[x]) num_abs.pop() num_abs.append(a) elif num_abs[0] == a: if array[x] < num[0]: num.pop() num.append(array[x]) num_abs.pop() num_abs.append(a) elif num_abs[0] <= a: continue answer = num[0] # 풀이 과정2 solution=lambda a,n:sorted(a,key=lambda x:(abs(x-n),x))[0]
  • Lv0 프로그래머스(Programmers)[Python][파이썬] x사이의 개수
    """ 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/courses/30/lessons/181867 """ # 풀이 과정 def solution(myString): k=myString.split("x") result=[] for x in k: z=len(x) result.append(z) return result
  • << 18 19 20 21 22 23 24 25 >>