Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions kakao_2021_blind/advertise_inserting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
def chagne_time_to_sec(time):
h, m, s = map(int, time.split(":"))

return h * 3600 + m * 60 + s

def change_sec_to_time(sec):
m, s = divmod(sec, 60)
h, m = divmod(m, 60)

h, m, s = map(str, [h,m,s])

h = h.zfill(2)
m = m.zfill(2)
s = s.zfill(2)

time = ":".join([h,m,s])
return time



def sum_watching_player(psum_of_time, logs):

for log in logs:
start_time, end_time = map(chagne_time_to_sec, log.split("-"))

psum_of_time[start_time] = psum_of_time[start_time] + 1
psum_of_time[end_time] = psum_of_time[end_time] -1


for i in range(1, len(psum_of_time)):
psum_of_time[i] = psum_of_time[i] + psum_of_time[i - 1]

def solution(play_time, adv_time, logs):
answer = ''

play_time_sec = chagne_time_to_sec(play_time)
psum_of_time = [0] * (play_time_sec + 1)

adv_time_sec = chagne_time_to_sec(adv_time)

sum_watching_player(psum_of_time, logs)

max_watching_time = 0
watching_time = 0
start_time_sec = 0

for i in range(1, adv_time_sec):
max_watching_time += psum_of_time[i-1]

watching_time = max_watching_time

for i in range(adv_time_sec, len(psum_of_time)):
watching_time = watching_time + psum_of_time[i - 1] - psum_of_time[i - adv_time_sec - 1]

if max_watching_time < watching_time:
max_watching_time = watching_time
start_time_sec = i - adv_time_sec

start_time = change_sec_to_time(start_time_sec)

return start_time




if __name__ == "__main__":
play_time = "99:59:59"
adv_time = "25:00:00"
logs = ["69:59:59-89:59:59", "01:00:00-21:00:00", "79:59:59-99:59:59", "11:00:00-31:00:00"]

print(solution(play_time, adv_time, logs))
54 changes: 54 additions & 0 deletions kakao_2021_blind/menu_renewal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from collections import Counter
from collections import defaultdict

import itertools

def solution(orders, course):
answer = []
cand_comb_menu = []

for num in course:
for order in orders:
comb_menues = list(itertools.combinations(order, num))

#AC, AD, AE
for comb_menu in comb_menues:
comb_menu = sorted(comb_menu)
cand_comb_menu.append("".join(comb_menu))

cand_comb_menu = Counter(cand_comb_menu).most_common()

best_like_dict = defaultdict(int)

for course_num in course:
best_like = 0

for menu, like in cand_comb_menu:
if len(menu) == course_num:
best_like = max(best_like, like)

best_like_dict[course_num] = best_like


for course_num in course:
if best_like_dict[course_num] == 0 or best_like_dict[course_num] < 2:
continue

for menu, like in cand_comb_menu:
if len(menu) == course_num and like == best_like_dict[course_num]:
answer.append(menu)

print(sorted(answer))
return answer


if __name__ == "__main__":
orders = ["ABCDE", "AB", "CD", "ADE", "XYZ", "XYZ", "ACD"]
course = [2,3,5]

solution(orders, course)





59 changes: 59 additions & 0 deletions kakao_2021_blind/searching_ranking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import bisect
from copy import deepcopy
from itertools import combinations


def make_sub_query(info):
keys = []
keys.append(" ".join(info))
for k in range(1, 5):
for sub in list(combinations(range(0, 4), k)):
case = deepcopy(info)

for idx in sub:
case[idx] = '-'

keys.append(" ".join(case))
return keys


def solution(infos, querys):

info_dict = {}

for info in infos:
lang, ground, pos, food, score = info.split()
query_set = make_sub_query([lang, ground, pos, food])

for q in query_set:
if q in info_dict.keys():
info_dict[q].append(int(score))
else:
info_dict[q] = [int(score)]

for key in info_dict.keys():
info_dict[key].sort()

answer = []

for q in querys:
q = q.replace(" and", "")
lang, ground, pos, food, score = q.split()

query_of_key = " ".join([lang, ground, pos, food])

if query_of_key in info_dict.keys():
score_list = info_dict[query_of_key]
answer.append(len(score_list) - bisect.bisect_left(score_list, int(score)))

else:
print("Asd")
answer.append(0)

return answer


if __name__ == "__main__":
info = ["java backend junior pizza 150","python frontend senior chicken 210","python frontend senior chicken 150","cpp backend senior pizza 260","java backend junior chicken 80","python backend senior chicken 50"]
query = ["java and backend and junior and pizza 100","python and frontend and senior and chicken 200","cpp and - and senior and pizza 250","- and backend and senior and - 150","- and - and - and chicken 100","- and - and - and - 150"]
print(solution(info, query))