Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

김영준 풀이 기록 #10

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "joon-leetcode"]
path = joon-leetcode
url = https://github.com/0BVer/leetcode.git
1 change: 1 addition & 0 deletions joon-leetcode
Submodule joon-leetcode added at 507bbc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def solution(n, k):
radix_k = convert(n, k)
p_list = str(radix_k).split('0')

return len([i for i in p_list if i not in ['', '1'] and check_prime(int(i))])

def convert(num, base):
power = 0
tmp = ''
while num:
tmp = str(num % base) + tmp
num //= base
return tmp

def check_prime(n): # 소수 검사
for i in range(2, round(n**(1/2)) + 1):
if n % i == 0:
return False

return True
17 changes: 17 additions & 0 deletions joon/src/programmers/kakao2022blind/신고 결과 받기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def solution(id_list, report, k):

report_set = set(report)
id_dict = {i: [] for i in id_list}
report_dict = {i: 0 for i in id_list}

for i in report_set:
temp = i.split(' ')
id_dict[temp[0]].append(temp[1])
report_dict[temp[1]] += 1

alert = [id for (id, v) in report_dict.items() if v >= k]

answer = []
for (i, l) in id_dict.items():
answer.append(len([c for c in l if c in alert]))
return answer
55 changes: 55 additions & 0 deletions joon/src/programmers/kakao2022blind/주차 요금 계산.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
def solution(fees, records):

records.sort()
in_log = {}
answer = {}

for i in records:
logs = i.split(' ')
if logs[2] == 'IN':
in_log[logs[1]] = logs[0]
else:
in_h, in_m = in_log[logs[1]].split(':')
out_h, out_m = logs[0].split(':')

in_m = int(in_m)
out_m = int(out_m)

in_m += int(in_h) * 60
out_m += int(out_h) * 60

if logs[1] in answer:
answer[logs[1]] += out_m - in_m
else:
answer[logs[1]] = out_m - in_m

del in_log[logs[1]]

for k, v in in_log.items():
in_h, in_m = v.split(':')
out_h, out_m = 23, 59

in_m = int(in_m)

in_m += int(in_h) * 60
out_m += out_h * 60

if k in answer:
answer[k] += out_m - in_m
else:
answer[k] = out_m - in_m

answer = dict(sorted(answer.items()))

a = []
for k, v in answer.items():
if v <= fees[0]:
a.append(fees[1])
else:
if (v - fees[0]) % fees[2] == 0:
a.append((v - fees[0]) // fees[2] * fees[3] + fees[1])
else:
a.append(((v - fees[0]) // fees[2] + 1) * fees[3] + fees[1])


return a
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from collections import deque

def solution(queue1, queue2):
# 적은 큐에서 큰 큐로 이동
# 반복을 중단 하는 경우 : 같아질때, 전체 큐 크기의 3배 돌렸을떄?

q1 = deque(queue1)
q2 = deque(queue2)

s1 = sum(q1)
s2 = sum(q2)

index = 0

if (s1 + s2) % 2 == 1:
return -1

while len(queue1) * 4 > index:
if s1 > s2:
temp = q1.popleft()
q2.append(temp)
s1 -= temp
s2 += temp
elif s2 > s1:
temp = q2.popleft()
q1.append(temp)
s2 -= temp
s1 += temp
else:
return index

index += 1

return -1
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
def solution(survey, choices):
mbti = [0, 0, 0, 0]
RT = 'RT', 'TR'
CF = 'CF', 'FC'
JM = 'JM', 'MJ'
AN = 'AN', 'NA'

for i in range(len(survey)):
if survey[i] in RT:
if survey[i][0] == 'T':
mbti[0] += choices[i] - 4
else:
mbti[0] -= choices[i] - 4
elif survey[i] in CF:
if survey[i][0] == 'F':
mbti[1] += choices[i] - 4
else:
mbti[1] -= choices[i] - 4
elif survey[i] in JM:
if survey[i][0] == 'M':
mbti[2] += choices[i] - 4
else:
mbti[2] -= choices[i] - 4
elif survey[i] in AN:
if survey[i][0] == 'N':
mbti[3] += choices[i] - 4
else:
mbti[3] -= choices[i] - 4

answer = ''

if mbti[0] >= 0:
answer += 'R'
else:
answer += 'T'

if mbti[1] >= 0:
answer += 'C'
else:
answer += 'F'

if mbti[2] >= 0:
answer += 'J'
else:
answer += 'M'

if mbti[3] >= 0:
answer += 'A'
else:
answer += 'N'

return answer
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def solution(today, terms, privacies):
t = {}
d = today.split('.')
d = [int(i) for i in d]
answer = []

for i in range(len(terms)):
t[terms[i][0]] = terms[i][2:]

for i in range(len(privacies)):
date = privacies[i][:-2].split('.')

if bigyo(d, date, t[privacies[i][-1]]):
answer.append(i + 1)

return answer

def bigyo(d, date, m):
date = [int(i) for i in date]

date[1] += int(m)
while date[1] > 12:
date[1] -= 12
date[0] += 1

if date[0] < d[0]:
return True
elif date[0] == d[0] and date[1] < d[1]:
return True
elif date[0] == d[0] and date[1] == d[1] and date[2] <= d[2]:
return True
return False
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def solution(cap, n, deliveries, pickups):
answer = 0

d = 0
p = 0

for i in range(n-1, -1, -1):

cnt = 0

d -= deliveries[i]
p -= pickups[i]

while d < 0 or p < 0:
d += cap
p += cap
cnt += 1

answer += (i + 1) * 2 * cnt

return answer
46 changes: 46 additions & 0 deletions joon/src/week10/N으로표현/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package week10.N으로표현;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution {
public int solution(int N, int number) {
List<Set<Integer>> countList = new ArrayList<>();

for (int i = 0; i < 9; i++)
countList.add(new HashSet<>());

countList.get(1).add(N); // N을 1개 쓴 값은 N 혼자이다.

for (int i = 2; i < 9; i++) {
Set<Integer> countSet = countList.get(i);

for (int j = 1; j <= i; j++) {
Set<Integer> preSet = countList.get(j);
Set<Integer> postSet = countList.get(i - j);

for (var preNum : preSet) {
for (int postNum : postSet) {
countSet.add(preNum + postNum);
countSet.add(preNum - postNum);
countSet.add(preNum * postNum);

if (preNum != 0 && postNum != 0)
countSet.add(preNum / postNum);
}
}
}

countSet.add(Integer.parseInt(String.valueOf(N).repeat(i)));
}

for (Set<Integer> sub : countList) {
if (sub.contains(number))
return countList.indexOf(sub);
}

return -1;
}
}
55 changes: 55 additions & 0 deletions joon/src/week11/등굣길/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package week11.등굣길;

import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Queue;

class Solution {

private static Location location = new Location(1, 1);
private static int m, n, answer;
private static boolean flag = true;
private static int [][] puddles;
private static Queue<Location> bfs = new LinkedList<>();

public int solution(int m, int n, int[][] puddles) {
this.m = m;
this.n = n;
this.puddles = puddles;
bfs.add(location);

while (flag) {
int size = bfs.size();

for (int i = 0; i < size; i++) {
Location l = bfs.poll();
insert(l.x + 1, l.y);
insert(l.x, l.y + 1);
}
}
return answer % 1000000007;
}

public void insert(int x, int y) {
if (x == m && y == n) {
flag = false;
answer++;
} else if (x <= m && y <= n) {
for (var j : puddles) {
if (j[0] == x && j[1] == y) {
return;
}
}
bfs.add(new Location(x, y));
}
}

static class Location {
int x, y;

public Location(int x, int y) {
this.x = x;
this.y = y;
}
}
}
2 changes: 1 addition & 1 deletion joon/src/week3/q_frozen_drink/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void main(String[] args) throws Exception {
bw.close();
}

private static void dfs(int x, int y) {
public static void dfs(int x, int y) {
if (grid[x][y]) {
grid[x][y] = false;
if (x - 1 > -1) {
Expand Down
Loading