코딩 테스트(7)
-
Lv.0 주사위 게임2
✏️ 문제 https://school.programmers.co.kr/learn/courses/30/lessons/181930 Python 1. set을 이용하여 중복된 요소를 제거하는 방법 def solution(a, b, c): answer = 0 # set을 적용하여 중복된 요소 제거 list_len = len(set[a,b,c]) print(list_len) if list_len == 3 : # 값이 모두 다른 경우 answer = a + b + c elif list_len == 2 : # 두 숫자가 같은 경우 # (a + b + c) × (a2 + b2 + c2 ) answer = (a + b + c) * (a ** 2 + b ** 2 + c ** 2) elif list_len == 1 : # ..
2023.12.07 -
Lv.0 코드 처리하기
✏️ 문제 https://school.programmers.co.kr/learn/courses/30/lessons/181932 Python def solution(code): mode = 0 # 0과 1이 존재, False ret = "" for idx in range(0, len(code)) : str = code[idx] if str == "1" : mode = not mode else : if (idx % 2 == mode): ret += str return "EMPTY" if ret == "" else ret 다른 사람의 문제 풀이 미쳤다... def solution(code): return "".join(code.split("1"))[::2] or "EMPTY" Java class Solutio..
2023.12.06 -
Lv.1 [PCCP 기출문제] 1번
✏️ 문제 Python def solution(bandage, health, attacks): # 초기 상태 설정 nowHealth = health # 현재 체력 success = 0 # 연속 성공 sec = 0 #현재 시간 t = bandage[0] # 시전 시간 x = bandage[1] # 초당 회복량 y = bandage[2] # 추가 회복량 while nowHealth > 0 and attacks : # 초 시간 증가 sec += 1 # 공격 시간 확인 if (attacks[0][0] == sec) : nowHealth -= attacks[0][1] success = 0 del attacks[0] if (nowHealth < 1) : return -1 else: # 초당 회복량 증가 nowHea..
2023.12.05 -
[프로그래머스] Lv.0 flag에 따라 다른 값 반환하기
✏️ 문제 https://school.programmers.co.kr/learn/courses/30/lessons/181933?language=python3 Python def solution(a, b, flag): return a + b if flag else a - b 다른 사람의 문제 풀이 lambda를 활용하는 방법에 대하여 검색해봐야겠다... solution=lambda a,b,f:[a-b,a+b][f] Java class Solution { public int solution(int a, int b, boolean flag) { return flag ? a + b : a-b; } }
2023.12.03 -
[프로그래머스] Lv.0 조건 문자열
✏️ 문제 https://school.programmers.co.kr/learn/courses/30/lessons/181934 Python def solution(ineq, eq, n, m): return int(eval(f"{n}{ineq}{eq.replace('!','')}{m}")) Java public int solution(String ineq, String eq, int n, int m) { boolean answer = true; if (eq.equals("=")) { answer = ineq.equals(">") ? n >= m : n m : n < m; } return (answer) ? 1 : 0; }
2023.12.03 -
[프로그래머스] Lv.0 문자열 반복해서 출력하기
✏️ 문제 https://school.programmers.co.kr/learn/courses/30/lessons/181950 Python a, b = input().strip().split(' ') b = int(b) print(a*b) JAVA import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); int n = sc.nextInt(); System.out.println(str.repeat(n)); } }
2023.12.02