춘식이2
업글이✧
춘식이2
전체 방문자
오늘
어제
  • 분류 전체보기
    • Data Analysis
    • Python
    • SQL
    • Statistics

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 데이터디스커버리
  • coalesce
  • uv
  • Codility
  • ifnull
  • pv
  • Apriori
  • 장바구니분석
  • SQL
  • rank함수
  • Jupyter
  • 데이터분석
  • python3
  • NVL
  • hackerrank
  • excel
  • NULL
  • Python
  • window함수
  • sql튜닝

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
춘식이2

업글이✧

Python

Programmers

2022. 7. 20. 17:47

Summer/Winter Coding(~2018) 예산 (test case 전부 통과)

d budget result
[1,3,2,5,4] 9 3
[2,2,3,3] 10 4

 

def solution(d, budget):
    d.sort()  # [1, 2, 3, 4, 5]
    answer = 0
    if sum(d) <= budget:
        answer += len(d)
    if sum(d) > budget :
        arr = []
        for i in d :
            if sum(arr) <= budget :
                arr.append(i)
            if sum(arr) > budget :
                pass
        answer += len(arr) -1
    return answer

ㅇ

def solution(n):
    answer = 0
    n = int(n)
    if n**(1/2) == int(n**(1/2)) :
        answer = (n**(1/2)+1)**2
    else :
        answer = -1
    return answer

 

def solution(s):
    
    num ={}
    num['one'] = 1
    num['two'] = 2
    num['three'] = 3
    num['four'] =4
    num['five'] = 5
    num['six'] = 6
    num['seven'] = 7
    num['eight'] = 8
    num['nine'] = 9
    num['ten'] = 10
    
    n_list = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight','nine', 'ten']
    ans_list =[]
    for i in range(len(s)) :
        if s[:i+1].isdigit() == True : 
            ans_list.append(s[:i+1])
            s = s[i+1:]
        if s[:i+1] in n_list :
            target = s[:i+1]
            change = num[target]
            ans_list.append(change)
            s = s[i+1:]
    print(ans_list)
    #answer = int("".join(ans_list))
    #return answer

input , output

s result
"one4seveneight" 1478
"23four5six7" 234567
"2three45sixseven" 234567
"123" 123

 

완주하지 못한선수 -> 런타임 에러

def solution(participant, completion):
    for i in range(len(completion)) :
        if completion[i] in participant :
            participant.remove(completion[i])
            answer = "".join(participant)
    return answer

 

모의고사 -> 런타임 에러

def solution(answers):
    ans1 = [1, 2, 3, 4, 5]
    ans2 = [2, 1, 2, 3, 2, 4, 2, 5] 
    ans3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
    score_1 = 0
    score_2 = 0
    score_3 = 0
    dict_score = {}
    for i in range(len(answers)) :
        if answers[i] == ans1[i] :
            score_1 += 1
            dict_score[1] = score_1
        if answers[i] == ans2[i] :
            score_2 += 1
            dict_score[2] = score_2
        if answers[i] == ans3[i] :
            score_3 += 1
            dict_score[3] = score_3
        answer = list(dict_score.keys())
        answer.sort()
    return answer

 

k번째 수 -> 런타임 에러

def solution(array, commands):
    ans = list()
    for i in [0, 1, 2]:
        fst = commands[i][0]
        sec = commands[i][1]
        thr = commands[i][2]

        new = array[fst-1 : sec]
        new.sort()
        answer = new[thr-1]
        ans.append(answer)
    return ans

'Python' 카테고리의 다른 글

pandas, numpy 라이브러리(평균, 표준편차, 공분산, 상관계수)  (0) 2022.08.21
Pandas 데이터 정렬하기, 날짜형 변환(to_datetime), pandasql, csv파일 불러오기/저장하기  (0) 2022.08.15
python 기초 _ for문 _ 중첩문  (0) 2022.07.16
python_if문, for문, def문, naming규칙, range  (0) 2022.07.14
Python3_기초  (0) 2022.07.12
    'Python' 카테고리의 다른 글
    • pandas, numpy 라이브러리(평균, 표준편차, 공분산, 상관계수)
    • Pandas 데이터 정렬하기, 날짜형 변환(to_datetime), pandasql, csv파일 불러오기/저장하기
    • python 기초 _ for문 _ 중첩문
    • python_if문, for문, def문, naming규칙, range
    춘식이2
    춘식이2

    티스토리툴바