>⛹️♀️ 제로베이스 데이터취업스쿨 15기 스터디노트 16(5.24.)
🗂️ 오늘(5.24.) 수강한 분량
알고리즘 문제풀이 4~5
🗂️ 알고리즘 문제풀이 4~5 ; 한번 더 생각해볼것 & 개념 부족한 것 정리
1-1.최빈값 알고리즘 : 회사 직원 나이 분포 모듈
- 최대값을 구하고 새로운 인덱스 생성
maxMod 모듈 for i, n in enmerate(self.nums): #최대값 반복인덱스 if self.maxNum < n: self.maxNum = n self.maxNumIdx = i modeMod 모듈 def setIndexList(self): self.indexes = [0 for i in range(self.maxNum + 1)] for n in self.nums: self.indexes[n] = self.indexes[n] + 1 `
-1-2.최빈값 알고리즘 : 로또 번호 빈도수 추출 모듈
mod 모듈 class LottoMode: def __init__(self, ln): self.lottoNums = ln self.modeList = [0 for n in range(1,47)] #46개의 값, 0은 쓰지않음, 로또의 번호를 저장(무슨 숫자가 많이 되엇는지) def getLottoNumMode(self): for roundNums in self.lottoNums: for num in roundNums: self.modeList[num] = sel.modeList[num] +1 #기존의 num에 1를 더한게 몇번인지 리스트에 저장
-2-2.근사값 알고리즘 : Bmi계산 알고리즘
near 모듈 class BmiAlgorithm: def __init__(self,w,h): ~~~~ self.userCondition = '' #문자입력 self.nearNum = 0 self.minNum = 0 #최고치 ~~~ def printUserCondition(self): for n in self.BMISection.keys(): absNum = abs(b - self.userBMI) if absNum < self.minNum: self.minNum = absNum self.nearNum = n #근사치로 바꿈
-3-1.재귀 알고리즘 : 전월대비 매출 증감액 나타내기
def salesUpAndDown(ss): if len(ss) == 1: return ss print(f'ss : {ss}') currentSales = ss.pop() #첫 데이터 제외 nextSalse =ss[0] increase = nextSales - currentSalses if increase > 0: increase = '+' + str(increase) #문자로 변환해서 + 표기해주기
-3-2.재귀 알고리즘 : 2개 정수 입력 후 큰 정수와 작은 정수 사이의 합 프로그램
mod 모듈 class NumsSum: def __init__(self, n1, n2): self.bigNum = 0 self.smallNum = 0 self.setN1N2(n1, n2) #자동초기화 ~~~ def addNum(self,n): if n <= 1: return n return n + self.addNum(n-1) #자기자신 호출후 자기보다 작은 수를 호출해서 계속 더해나가기
-4-1.평균 알고리즘 : 경기 점수의 최댓값, 최솟값 제외한 나머지 점수 평균을 구한 후 순위 구하기
max 모듈 class MaxAlgorithm: ~~ def removeMaxScore(self): self.maxScore = self.scores[0] #초기값 near모듈 class top5Players: def __init__(self, cts, ns): ~~~ else: for i in range(len(self.currentScores) - 1, nearIdx+1, -1): self.currentScores[i] = self.currentScores[i - 1] self.currentScores[nearIdx+1] = self.newScore #그 다음에 삽입이 되어야 함 def getFinalTopScores(self): return self.currentScores
-4-2.평균 알고리즘 : 전체 평균과 홍길동학생의 점수의 차이(과목별, 평균점수) 출력하기
- 각 과목별 총 점수 → 각 과목별 평균 → 각 과목별 차이 → 전체 총점수, 평균 → 홍길동 총 점수, 평균 → 총 점수, 평균차이 구하기
👩🚀 스터디 감정 노트
ㅋㅋ다시 복습하러 가자! 그리고 다시 또 보다보면 하겠지 코딩테스트 할수 있다(못해도 어째..다시 해야지) 중요한 건 꺽이지 않은 마음 😫
[이미지 출처 : 미리캔버스]