[PS(Problem Solving)]/[백준]

    [백준] 25206 파이썬(python): 너의 평점은

    [백준] 25206 파이썬(python): 너의 평점은

    25206번: 너의 평점은 평점 구하는 법을 까먹어서 해맷던 문제다. 에브리타임을 이용하면 학점 자동계산이라 한번도 생각해보지 않았다. import sys grade = { 'A+' : 4.5, 'A0' : 4.0, 'B+' : 3.5, 'B0' : 3.0, 'C+' : 2.5, 'C0' : 2.0, 'D+' : 1.5, 'D0' : 1.0, 'F' : 0.0 } rate = 0 scoresum = 0 for _ in range(20): score = sys.stdin.readline().split() if score[2] != 'P': rate += float(score[1]) * grade[score[2]] scoresum += float(score[1]) print(f'{rate/scoresum:...

    [백준] 2587 파이썬(python): 대표값2

    [백준] 2587 파이썬(python): 대표값2

    2587번: 대표값2 import sys numbers, res = [], 0 for _ in range(5): num = int(sys.stdin.readline()) res += num numbers.append(num) numbers.sort() print(res // 5) print(numbers[len(numbers)//2])

    [백준] 1076 파이썬(python) : 저항

    [백준] 1076 파이썬(python) : 저항

    1076번 : 저항 import sys color = { 'black' : 0, 'brown' : 1, 'red' : 2, 'orange' : 3, 'yellow' : 4, 'green' : 5, 'blue' : 6, 'violet' : 7, 'grey' : 8, 'white' : 9 } number = { 0 : 1, 1 : 10, 2 : 100, 3 : 1000, 4 : 10000, 5 : 100000, 6 : 1000000, 7 : 10000000, 8 : 100000000, 9 : 1000000000 } arr = [ sys.stdin.readline().rstrip() for _ in range(3) ] res = 0 res = (color[arr[0]]*10 + color[arr[1]]) * ..

    [백준] 2822 파이썬(python) : 점수 계산

    [백준] 2822 파이썬(python) : 점수 계산

    2822번 : 점수 계산 import sys hash = {} number = [] for i in range(8): #1 score = int(sys.stdin.readline()) if score not in hash: #2 hash[score] = i+1 number.append(score) #3 number.sort() #4 res = 0 tmp = [] for i in range(3, len(number)): #5 res += number[i] #6 tmp.append(hash[number[i]] ) #7 print(res) tmp.sort() #8 print(*tmp) #1 : 8개의 점수가 주어짐 #2 : 주어진 점수가 hash안에 없을때 키-값으로 인덱스+1을 넣어줌 #3 : 주어진 점수를..

    [백준] 1934 파이썬(python) : 최소공배수

    [백준] 1934 파이썬(python) : 최소공배수

    1934번 : 최소공배수 import sys t = int(sys.stdin.readline()) def gcd(a, b): while b > 0: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) for _ in range(t): a, b = map(int, sys.stdin.readline().split()) print(lcm(a, b)) 유클리드 호제법을 이용하면 쉽게 풀 수 있는 문제다. 최대공약수 구하는 함수를 만들고 그 함수를 이용해서 최소 공배수를 생성하는 함수를 만들면 되는데 오랫만에 풀어서 함수가 기억이 안나 예전 포스팅을 참고했다. 파이썬에서는 math모듈을 import해서 최대공약수, 최소공배수를 구할 수 있지만 유클..

    [백준] 1037 파이썬(python) : 약수

    [백준] 1037 파이썬(python) : 약수

    1037번 : 약수 import sys n = int(sys.stdin.readline()) aliquot = list(map(int, sys.stdin.readline().split())) aliquot.sort() #1 res = aliquot[0] * aliquot[-1] #2 print(res) #1 : 약수들을 정렬 #2 : 정렬한뒤 약수들의 가장 첫번째 원소와 가장 마지막 원소를 곱하면 원하는 N이 나온다