반응형

boj 16

백준 알고리즘 [파이썬] 4673 셀프넘버

4673번 셀프넘버 4673번: 셀프 넘버 셀프 넘버는 1949년 인도 수학자 D.R. Kaprekar가 이름 붙였다. 양의 정수 n에 대해서 d(n)을 n과 n의 각 자리수를 더하는 함수라고 정의하자. 예를 들어, d(75) = 75+7+5 = 87이다. 양의 정수 n이 주어졌을 때, www.acmicpc.net #4673 셀프넘버 문제 셀프 넘버는 1949년 인도 수학자 D.R. Kaprekar가 이름 붙였다. 양의 정수 n에 대해서 d(n)을 n과 n의 각 자리수를 더하는 함수라고 정의하자. 예를 들어, d(75) = 75+7+5 = 87이다. 양의 정수 n이 주어졌을 때, 이 수를 시작해서 n, d(n), d(d(n)), d(d(d(n))), ...과 같은 무한 수열을 만들 수 있다. 예를 들어,..

Data/Python 2021.06.25

백준 알고리즘 [파이썬]: 6. 함수 : 15596 정수 N개의 합

6.함수 함수 단계 함수를 구현해 봅시다. (이 문제는 C, C++, Python, Java, Go만 지원합니다. 그 외의 언어를 사용하신다면 이 문제를 무시해 주세요.) www.acmicpc.net #15596 정수 N개의 합 def solve(a): return sum(a) solve=sum Python 함수는 first class 객체이다. 변수에 함수 할당함 함수는 객체타입의 인스턴스 함수에 변수를 저장할수 있다 다른 함수에 파라미터로 넘길 수 있다 함수로부터 함수를 리턴할 수 있다. 자료구조에 함수를 저장할 수 있다.

Data/Python 2021.06.24

백준 알고리즘 [파이썬]: 5. 1차원 배열

5. 1차원 배열-1 1차원 배열 단계 각 숫자가 몇 번 나왔는지 저장하기 위해 일차원 배열을 만드는 문제 www.acmicpc.net #10818 최소, 최대 N = int(input()) arr = list(map(int, input().split())) print(min(arr), max(arr)) #2562 최댓값 arr=[] for i in range(0): arr.append(int(input())) print(str(max(arr))+'\n'+str(arr.index(max(arr))+1)) index : 위치 값 받기(0부터 시작해서 1을 더함) #2577 숫자의 개수 A = int(input()) B = int(input()) C = int(input()) num_list = list(s..

Data/Python 2021.06.22

백준 알고리즘 [파이썬]: 4. While 문

4. While 문 while문 단계 입력이 끝날 때까지 A+B를 출력하는 문제. EOF에 대해 알아 보세요. www.acmicpc.net #10952번 (A+B -5) a,b = map(int, input().split()) while (a!=0 and b!=0): print(a+b) a, b=map(int,input().split()) 0 0 을 입력하면 print 하지 않고 바로 끝남 #10951번 (A+B -4) while True: try: a,b = map(int,input().split()) print(a+b) except: break 입력하지 않고 끝내면 ValueError: not enough values to unpack (expected 2, got 0) 가 나오므로 try ~exce..

Data/Python 2021.06.21

백준 알고리즘 [파이썬]: 3. for문

3.for 문 for문 단계 1부터 N까지의 합을 구하는 문제. 물론 반복문 없이 풀 수도 있습니다. www.acmicpc.net #2739 구구단 i=int(input()) for j in range(1,10): print(i, '*' ,j, '=', i*j) #10950 A+B - 3 for _ in range(int(input())): print(sum(list(map(int,input().split())))) #8398 합 total=0 for i in range(int(input())+1): total += i print(total) #15552 빠른 A+B import sys T = int(sys.stdin.readline()) for i in range(T): a, b = map(int,sy..

Data/Python 2021.06.20

백준 알고리즘 [파이썬]: 2.if문

2.if문 if문 단계 점이 어느 사분면에 있는지 알아내는 문제 www.acmicpc.net #1330 두 수 비교하기 a,b =map(int, input().split()) if a>b: print('>') elif a=90: print('A') elif score >=80: print('B') elif score >=70: print('C') elif score >=60: print('D') else : print('F') #2753 윤년 leap_year = int(input()) if leap_year %4==0 and (leap_year%100!=0| leap_year %400==0) : print(1) else: print(0) #14681사분면 고르기 x=int(input()) y=int(i..

Data/Python 2021.06.19
반응형