본문 바로가기

Algorithm/BAEKJOON8

[BAEKJOON] 알고리즘 분류_구현 (2741, 2577, 2750, 10817, 10250) # 2741 : N 찍기 IDEA for문을 이용해서 출력한다. 풀이 n = int(input()) for i in range(1, n+1): print(i) # 2577 : 숫자의 개수 IDEA count 함수를 이용한다. 풀이 a = int(input()) b = int(input()) c = int(input()) n = str(a*b*c) for i in range(10): print(n.count(str(i))) count 함수 string.count(str, start, end) # 2750 : 수 정렬하기 IDEA sort 함수를 이용한다. 풀이 n = int(input()) n_list = list() for i in range(n): n_list.append(int(input())) n_.. 2023. 5. 2.
[BAEKJOON] 단계별로 풀어보기 25. 그리디 알고리즘 https://www.acmicpc.net/step/33 그리디 알고리즘 단계 동전의 조건이 특별해서 동적 프로그래밍보다 빠르게 답을 찾을 수 있는 문제 www.acmicpc.net # 11047 : 동전 0 IDEA 가장 큰 화폐 단위부터 나누어 계산한다. 풀이 n, k = map(int, input().split()) count = 0 coin_types = [] for i in range(n): coin_types.append(int(input())) coin_types.sort(reverse=True) for coin in coin_types: count += k // coin k %= coin print(count) print(coin_types) 동전 종류를 입력 받고, 내림차순 정렬을 해준다.. 2023. 4. 10.
[BAEKJOON] 단계별로 풀어보기 6. 문자열 https://www.acmicpc.net/step/7 문자열 단계 정수를 문자열로 입력받는 문제. Python처럼 정수 크기에 제한이 없다면 상관 없으나, 예제 3은 일반적인 정수 자료형에 담기에 너무 크다는 점에 주목합시다. www.acmicpc.net # 11654 : 아스키 코드 a = input() print(ord(a)) ord() 문자에 맞는 아스키코드(숫자값) 출력 chr() 아스키코드에 해당하는 문자 출력 # 11720 : 숫자의 합 n = input() result = 0 num_list = input() for i in num_list: result += int(i) print(result) # 10809 : 알파벳 찾기 s = input() abc_list = [chr(i) for .. 2022. 10. 1.
[BAEKJOON] 단계별로 풀어보기 5. 함수 https://www.acmicpc.net/step/5 함수 단계 함수를 구현해 봅시다. (이 문제는 C, C++, Python, Java, Go만 지원합니다. 그 외의 언어를 사용하신다면 이 문제를 무시해 주세요.) www.acmicpc.net # 15596 : 정수 N개의 합 def solve(a): ans = sum(a) return ans # 4673 : 셀프 넘버 def self_number(): num_set = set(range(10001)) not_self_num_set = set() for i in range(10001): not_self_num_set.add(i + i%10 + (i//10)%10 + (i//100)%10 + (i//1000)%10 + (i//10000)%10) resu.. 2022. 9. 16.
[BAEKJOON] 단계별로 풀어보기 4. 1차원 배열 https://www.acmicpc.net/step/6 1차원 배열 단계 OX 퀴즈의 결과를 일차원 배열로 입력받아 점수를 계산하는 문제 www.acmicpc.net # 10818 : 최소, 최대 # 10818 n = int(input()) n_list = list(map(int, input().split())) print(min(n_list), max(n_list)) 굳이 n을 입력 받을 필요가 없는 문제이지않나...? # 2562 : 최댓값 n_list = [] for i in range(9): a = int(input()) n_list.append(a) print(max(n_list)) print(n_list.index(max(n_list))+1) # 3052 : 나머지 n_list = [] for.. 2022. 9. 13.
[BAEKJOON] 단계별로 풀어보기 3. 반복문 https://www.acmicpc.net/step/3 반복문 단계 1부터 N까지의 합을 구하는 문제. 물론 반복문 없이 풀 수도 있습니다. www.acmicpc.net # 2739 : 구구단 N = int(input()) for i in range(1, 10): print("{} * {} = {}".format(N, i, N*i)) # 10950 : A+B - 3 T = int(input()) for i in range(T): a, b = map(int, input().split()) print(a+b) # 8393 : 합 n = int(input()) result = 0 for i in range(1, n+1): result += i print(result) a += i : a = a + i # 25.. 2022. 9. 10.
[BAEKJOON] 단계별로 풀어보기 2. 조건문 https://www.acmicpc.net/step/4 조건문 단계 점이 어느 사분면에 있는지 알아내는 문제 www.acmicpc.net # 1330 : 두 수 비교하기 a, b = map(int, input().split()) if a > b: print(">") elif a < b: print(" 2022. 9. 9.
[BAEKJOON] 단계별로 풀어보기 1. 입출력과 사칙연산 https://www.acmicpc.net/step/1 입출력과 사칙연산 단계 입출력과 사칙연산 www.acmicpc.net # 2557 : Hello World print("Hello World!") # 10718 : We love krili print("강한친구 대한육군\n강한친구 대한육군") \n : 줄바꿈 # 1000 : A+B a, b = map(int, input().split()) print(a + b) map 여러 요소에 하나의 함수를 한꺼번에 대응시켜줌 저장할 변수 = map(함수 이름, 대응할 일련의 요소) split 복수 개의 입력값을 쪼개어주는 용도 저장할 변수 = 문자열.split() 구분자 sep : split(sep = ":") => :을 기준으로 입력값 쪼갬 # 1001 : .. 2022. 9. 9.