728x90

못 풀었다. 알고리즘은 알겠는데 마지막 구현 과정에서 꼬였다. in_car 이랑 out_car 까지는 다 구현 했는데 마지막에서 막혔다. 

 

def fee(n,fees):
    # n은 분
 
    total = 0 
 
    if n<=fees[0]:
        return fees[1]
    else:
        total += fees[1]
 
 
        n -= fees[0]
 
 
        total += int(n/fees[2])*fees[3]
 
        return total
 
 
def solution(fees, records):
    answer = []
 
    in_car = [ ]
 
    out_car = [ ]
 
    for i in range(0,len(records)):
        k = records[i].split(" ")
 
        m = k[0].split(":")
 
        minute = int(m[0])*60 + int(m[1])     
 
        put = [ ]
 
        put.append(k[1])
        put.append(minute)
 
        if k[2]=="IN":
            in_car.append(put)           
 
 
        else:
            out_car.append(put)
 
 
    in_car = list(sorted(in_car))
    out_car = list(sorted(out_car))
 
    # in_car 차 번호에 따른 합 구하기 (중복 제거 위해 리스트 생성)
 
    # out_car에서 그 차 번호의 합 구하고 만약 개수가 다르다면 23*60+59 추가해주기
 
    compare= [ ]
 
 
    for i in range(0,len(in_car)):
        total = 0 
 
        for q in range(0,len(out_car)):
            if out_car[q][0]==in_car[i][0]:
                total += out_car[q][1]
 
        if out_car.count(in_car[i][0]) != in_car.count(in_car[i][0]):
            total += (23*60+59)
 
 
        if in_car[i][0] in compare:
            continue
        else:
            count = in_car.count(in_car[i][0])
 
            for j in range(i+1,len(in_car)):
                if in_car[i][0] == in_car[j][0]:
                    total -= in_car[j][1]
            compare.append(in_car[i][0])       
 
            answer.append(fee(total,fees))
 
 
 
 
    print(compare) 
 
 
    print(in_car) 
    print(out_car)
    return answer
728x90

+ Recent posts