[프로그래머스] 짝수와 홀수
[프로그래머스] 짝수와 홀수
2020.10.10def solution(num): if num % 2 == 0: return "Even" else : return "Odd" 기본 문제이다.
[프로그래머스] 최대공약수와 최소공배수
[프로그래머스] 최대공약수와 최소공배수
2020.10.10def solution(n, m): def gcd(x,y): while(y): x,y = y, x%y return x def lcm(x,y): result = (x*y)//gcd(x,y) return result x = gcd(n,m) y = lcm(n,m) return (x,y) 유클리오 호제법을 이용한 방법이다.
[프로그래머스] x만큼 간격이 있는 숫자
[프로그래머스] x만큼 간격이 있는 숫자
2020.10.09def solution(x, n): result = [] for i in range(1,n+1): result.append(x * i) return result
[프로그래머스] 제일 작은수 제거하기
[프로그래머스] 제일 작은수 제거하기
2020.10.09def solution(arr): if arr[0] == 10 : return [-1] else : temp = min(arr) result = arr.remove(temp) return arr min 함수를 통해서 리스트의 최소 값을 구하고, remove 함수를 통해 최소 값을 제거한다.
[백준] 4673 - 셀프 넘버 (파이썬 / C++)
[백준] 4673 - 셀프 넘버 (파이썬 / C++)
2020.04.09general = set(range(1, 10001)) change = set() for i in range(1, 10001): for j in str(i): i += int(j) change.add(i) result = general - change for i in sorted(result): print(i) #include using namespace std; bool selfnum[10001]; int main(void) { memset(selfnum, true, sizeof(selfnum)); for(int i=1; i
[백준] 15596 - 정수 N개의 합 (파이썬)
[백준] 15596 - 정수 N개의 합 (파이썬)
2020.04.09def solve(a): ans = 0 for i in a: ans += i return ans
[백준] 4344 - 평균은 넘겠지 (파이썬) (C)
[백준] 4344 - 평균은 넘겠지 (파이썬) (C)
2020.04.09import sys input = sys.stdin.readline N = int(input()) for i in range(N): list_temp = list(map(int, input().split(' '))) average = sum(list_temp[1:]) / list_temp[0] count = 0 for j in list_temp[1:]: if j > average: count += 1 print(str('%.3f' % round(count / list_temp[0] * 100, 3)) + '%') #include int main() { int num; float sum=0; float count=0; int stu_num; int score[1000]; scanf("%d", &num); ..
[백준] 8958 - OX퀴즈 (파이썬) (C++)
[백준] 8958 - OX퀴즈 (파이썬) (C++)
2020.04.09N = int(input()) for i in range(N): score = 0 cnt = 0 result = input() for j in range(len(result)): if result[j] == 'O': cnt += 1 score += cnt elif result[j] == 'X': score += 0 cnt = 0 print(score) #include #include using namespace std; int main() { int num; cin >> num; int *save_total = new int[num]; for (int i = 0; i > answer; for..
[백준] 1546 - 평균 (파이썬)
[백준] 1546 - 평균 (파이썬)
2020.04.08N = int(input()) score = list(map(int, input().split())) modify = [] for i in score: modify.append(i/max(score) * 100) print("%0.2f" % (sum(modify) / N)) 먼저 N에 과목의 개수를 입력받는다. 그후 list와 map, split을 통해서 과목의 점수를 score 리스트에 담는다. 그후 조작하고 나서 저장할 변수은 modify를 선언한다. 그후 score에서 값을 하나씩 꺼내와서 score의 가장 높은 점수로 나눠주고, 100을 곱해주고 modify 변수에 저장한다. 그후 마지막에 모든 modify 값들을 더하고 과목의 개수로 나눠주면, 조작된 평균을 구할 수 있다.
[백준] 3052 - 나머지 (파이썬)
[백준] 3052 - 나머지 (파이썬)
2020.04.08num_list = [] for i in range(10): temp = int(input()) num_list.append(temp % 42) num_list = set(num_list) print(len(num_list)) 먼저 num_list의 배열을 선언하고, 10개의 수를 입력받는다. 수를 입력 받음과 동시에 주어진 조건인 42로 나눠주고, 나머지를 num_list에 저장한다. 그 후 set 함수를 통해서 중복 값을 제거해주고, 리스트의 개수를 출력한다.
[백준] 2577 - 숫자의 개수 (파이썬)
[백준] 2577 - 숫자의 개수 (파이썬)
2020.04.08A = int(input()) B = int(input()) C = int(input()) result = A * B * C temp = str(result) for i in range(0,10): print(temp.count(str(i)))
[백준] 2562 - 최대값 (파이썬)
[백준] 2562 - 최대값 (파이썬)
2020.04.08num_list = [] for i in range(9): temp = int(input()) num_list.append(temp) max_result = max(num_list) print(max_result) print(num_list.index(max_result) + 1)
[백준] 10818 - 최소, 최대 (파이썬)
[백준] 10818 - 최소, 최대 (파이썬)
2020.04.06a = int(input()) num_list = list(map(int, input().split())) print('{} {}'.format(min(num_list), max(num_list)))
[백준] 10996 - 별 찍기 - 21 (파이썬)
[백준] 10996 - 별 찍기 - 21 (파이썬)
2020.04.05N = int(input()) if N == 1: print('*') else: if N % 2 == 0: a = '* ' * (N//2) b = ' *' * (N//2) else: a = '* ' * (N//2) + '*' b = ' *' * (N//2) for i in range(N): print(a) print(b)
[백준] 2446 - 별 찍기 - 9 (파이썬)
[백준] 2446 - 별 찍기 - 9 (파이썬)
2020.04.05a = int(input()) for i in range(1, a + 1): print(" " * (i - 1) + "*" * (2 * (a - i) + 1)) for j in range(1, a): print(" " * (a - j - 1) + "*" * (2 * j + 1))