본문 바로가기

프로그래밍/Baekjoon

(52)
(파이썬) 백준 알고리즘 15650번 N과 M(2) 문제풀이 (Python) 123456789101112131415161718import sysn,m = map(int,input().split())c = [False]*(n+1)a = [0]*m def go(index, start, n, m): if index == m: sys.stdout.write(' '.join(map(str,a))+'\n') for i in range(start, n+1): if c[i]: continue c[i] = True a[index] = i go(index+1, i+1, n, m) c[i] = False go(0,1,n,m) Colored by Color Scriptercs 1. 재귀 함수를 사용하여 수열을 만듦2. 중복이 불가능 하기 때문에 check를 사용하여 True이..
(파이썬) 백준 알고리즘 15649 번 N과 M(1) 문제풀이 (Python) 12345678910111213141516171819202122n,m = map(int,input().split()) check = [False]*(n+1)a = [0]*m def go(index, n, m): if index == m: for i in range(m): print (a[i], end = ' ') print() return for i in range(1, n+1): if check[i]: continue check[i] = True a[index] = i go(index+1, n, m) check[i] = False go(0,n,m) Colored by Color Scriptercs 1. 재귀 함수를 사용하여 수열을 만듦2. 중복이 불가능 하기 때문에 check를..
(파이썬) 백준 알고리즘 2309번 일곱 난쟁이 문제 풀이 (Python) 123456789101112131415161718192021n = []for i in range(9): n.append(int(input())) n.sort()total = sum(n)tmp = [] flag = Truefor i in range(len(n)): for j in range(i+1, len(n)): if (total - n[i] - n[j]) == 100: for k in range(len(n)): if i == k or j == k: continue print(n[k]) flag = False break if flag == False: break Colored by Color Scriptercs 1. 일곱 난쟁이의 키의 합은 100이다.2. 아홉명의 키의 합에서..
(파이썬) 백준 알고리즘 2920번 문제풀이 (Python) 123456789a = list(map(int, input().split())) if a == sorted(a): print('ascending')elif a == sorted(a, reverse=True): print('descending')else: print('mixed') Colored by Color Scriptercs키워드 (Keyword)sorted리스트를 정렬 (새로운 리스트 리턴 O)디폴트는 오름차순 정렬해주며 내림차순 정렬시 sorted(list,reverse=True)로 사용한다. 참조장삼용, 초보자를 위한 파이썬 200제, 정보문화사(2017)문제 출처https://www.acmicpc.net/problem/2920
(파이썬) 백준 알고리즘 8958번 문제풀이 (Python) 123456789101112131415161718192021n = int(input()) # 리스트 초기화list = ['' for i in range(n)]count = [0 for i in range(n)] for i in range(n): list[i] = input() for i in range(n): an = 1 for j in range(len(list[i])): if list[i][j] == 'O': count[i] += an an += 1 else: an = 1 for i in range(n): print(count[i]) Colored by Color Scriptercs키워드 (Keyword)문제 출처https://www.acmicpc.net/problem/8958
(파이썬) 백준 알고리즘 2577번 문제 풀이 (Python) 12345678910111213result = 1 count = [0 for i in range(10)] for i in range(3): result *= int(input()) for i in range(len(str(result))): index = int(str(result)[i]) count[index] += 1 for i in range(10): print(count[i])cs키워드 (Keyword)문제 출처https://www.acmicpc.net/problem/2577
(파이썬) 백준 알고리즘 1152번 문제풀이 (Python)123n = input().split() print(len(n))cs키워드 (Keyword)lenlen(s)은 입력값 s의 길이(요소의 전체 개수)를 리턴하는 함수이다. 참조https://wikidocs.net/book/1 (점프 투 파이썬-WikiDocs)문제 출처https://www.acmicpc.net/problem/1152
(파이썬) 백준 알고리즘 1065번 문제풀이 (Python) 123456789101112131415161718192021222324252627282930# 세자리 수 부터 한수 인지 확인하는 함수def check_num(num, length): sum = 0 #첫째 자리 수와 둘째 자리수의 차를 확인 (공차를 구함) x = int(num[0]) - int(num[1]) flag = True for i in range(1, length-1): #각 자리수와 다음자리수의 차를 확인 (공차와 같은지 확인) if x == int(num[i]) - int(num[i+1]): continue else: flag = False return flag a = input()cnt = 0 for i in range(1,int(a)+1): #1~99는 한 수 ..