본문 바로가기

프로그래밍/프로그래머스

프로그래머스 등수 매기기 object Solution { def solution(score: Vector[Vector[Int]]): Vector[Int] = { def avg(x:Vector[Int]):Int= (x(0)+x(1))/2 def filList(idx:Int=0,lst:List[Int]=List()):List[Int]={ if(idx==score.length) lst else filList(idx+1,lst ::: List(avg(score(idx)))) } val originList = filList() //[70,80,75,90] 평균이 적혀있는 리스트 val sortedList = (filList().sorted).reverse //[90,80,75,70]으로 정렬 def ranker(idx:Int=0,arr:.. 더보기
숨어있는 숫자의 덧셈 solution code Solution 1 아 문제를 아예 잘못읽고 삽질했다. def solution(my_string: String): Int = { val str = my_string.sorted def filter(idx:Int=0, res:String =""):String={ if(idx==my_string.length) res else{ if(str(idx).toInt>57) str.slice(0,idx) else filter(idx+1,res) } } val lst:List[Char] = filter().toList def sum(idx:Int=0, count:Int = 0):Int={ if(idx==lst.length) count else sum(idx+1, count-48+lst(idx).toInt) } sum(.. 더보기
다항식 더하기 solution code Solution 1) def solution(polynomial: String): String = { val arr:Array[String] = polynomial.split(" ") val num:Int = arr.length def x_list(idx:Int=0, lst:List[String]=List()):List[String]={ if(idx==num) lst else{ if((arr(idx).length>1)&&(arr(idx)(1).toString=="x")) x_list(idx+1,lst:::List(arr(idx)(0).toString)) else if (arr(idx)=="x") x_list(idx+1, lst:::List("1")) else x_list(idx+1,lst) } } def.. 더보기
프로그래머스 한 번만 등장한 문자 solution code Solution 1. object Solution { def solution(s: String): String = { val sorted_str: String = s.sorted + "1" def func(idx: Int, res: String = ""): String = { if (idx >= s.length) res else { if (sorted_str(idx) == sorted_str(idx + 1)) func(idx + 2, res) else if ((idx!=0)&&(sorted_str(idx) == sorted_str(idx - 1))) func(idx + 2, res) else func(idx + 1, res + sorted_str(idx)) } } func(0) } } 첫번째 코드는 테스.. 더보기
최빈값 return from collections import Counter def solution(array): c = Counter(array) order = c.most_common() maximum = order[0][1] modes = [] for num in order: if num[1] == maximum: modes.append(num[0]) if len(modes)>=2: return -1 else: return modes[0] object Solution { def sol(array: List[Int]): Int = { def counterlist(array: List[Int], idx: Int, count: Int = 1): List[Int] = { if (idx == array.length - 1) c.. 더보기
11/18 FRI 프로그래머스 분수의 덧셈 https://azu87.notion.site/11-22-11-18-3d597fc9002b46b2a2812cce2a78ca71 https://docs.google.com/spreadsheets/d/1BzoWwQawl0rQIknj3hoypvY5IZ0fw_ebH-dlQ08fVrg/htmlview# 계산과학 과제 급하게 하다가 꽃힌 프로그래머스.. 백준은 컴파일 에러도 너무 많이 나고 좀 난해?해서 손이 잘 안갔는데 이건 코드만 단순히 쳐도 괜찮고 간단히 테스트케이스들을 돌려볼 수 있어서 너무너무 좋았다. 그러다가 살짝 난관에 봉착했던 문제이다. 최대공약수, 최소공배수를 사용해서 최대한 멍청하게 코드를 짜봤는데.... 조금 더 고민하면 코드를 줄일 수는 있을 것 같은데 귀찮아서 패스 ..... GCD, LCM.. 더보기