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
70 changes: 70 additions & 0 deletions 15주차/(P)17679/(P)17679_Python_노유빈.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 나머지 테스트 코드는 통과했지만 테스트 코드 10번 정확성 실패, 테스트 코드 2번 효율성 실패이다.




# 제거되는 블럭들을 '0' 으로 치환 후 제거한 후 값이 '0'인 블럭 위의 블럭이 대치 후 list 리턴 해주기. 제거되는 블럭이 없다면 false 리턴.

def remove(a):
list = []

# 제거될 블럭 중 가장 왼쪽위 의 블럭의 좌표를 list 에 담기.
for i in range(0,len(a)-1):
for j in range(0,len(a[0])-1):
if a[i][j]==a[i+1][j] and a[i][j]==a[i][j+1] and a[i][j]==a[i+1][j+1]:
list.append([i,j])


# list 가 비었으면 false 리턴
if len(list)==0:
return False

else:
# 비었지 않다면 그 블럭 포함 4개의 블럭 값을 '0' 으로 치환.
for i in range(0,len(list)):
a[list[i][0]][list[i][1]]='0'
a[list[i][0]+1][list[i][1]]='0'
a[list[i][0]][list[i][1]+1]='0'
a[list[i][0]+1][list[i][1]+1]='0'

# 아래 블럭의 값이 '0' 이라면 자신의 값을 '0' 으로 바꾸고 아래 블럭 값을 자신의 블럭 값으로 바꾸기.
for i in range(0,len(a)-1):
for j in range(0,len(a[0])):
if a[i+1][j] == '0':
a[i+1][j] = a[i][j]
a[i][j] = '0'

# 변경된 리스트 리턴
return a




def solution(m, n, board):

# m:높이, n:폭

answer = 0
a = [ ]

str = [ ]

# board를 문자를 기준으로 나누고 리스트에 저장

for i in range(0,len(board)):
for j in range(0,len(board[i])):
str.append(board[i][j])
a.append(str)
str = []

# compare 함수에서 false 조건이 잘 나오지 않아 반복문으로 돌림
for i in range(0,m*n):
a=remove(a)


# 값이 '0' 인 블럭이 제거된 블럭이기에 그 수를 셈.
for i in range(0,len(a)):
answer += a[i].count('0')


return answer
89 changes: 89 additions & 0 deletions 15주차/2146/(P)72412_python_노유빈.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

# 정확성은 통과했지만 효율성을 통과하지 못했다.



# 리스트 a,b 비교 함수 (Score 제외, 조건이 일치하는 않는 것이 하나라도 있으면 False 반환 )

def compare(a,b):
for i in range(0,len(b)):
if b[i] not in a:
return False

return True


# Score 비교 함수

def score_compare(a,b):
a_score = ""
b_score = ""

for i in range(0,len(a)):
if a[i].isdigit()==True:
a_score+=a[i]

for i in range(0,len(b)):
if b[i].isdigit()==True:
b_score+=b[i]

return int(a_score)>=int(b_score)




def solution(info, query):
answer = 0

ans = []

# 2차원 리스트 초기화

a = [[]*2 for i in range(len(query))]


# query의 각 항목들을 추출해서 리스트 a에 넣기

for i in range(len(query)):
if "cpp" in query[i]:
a[i].append("cpp")

if "java" in query[i]:
a[i].append("java")

if "python" in query[i]:
a[i].append("python")

if "backend" in query[i]:
a[i].append("backend")

if "frontend" in query[i]:
a[i].append("frontend")

if "junior" in query[i]:
a[i].append("junior")

if "senior" in query[i]:
a[i].append("senior")

if "chicken" in query[i]:
a[i].append("chicken")

if "pizza" in query[i]:
a[i].append("pizza")



# compare 함수를 이용해서 조건에 맞는 answer 개수 세기

for i in range(0,len(a)):
for j in range(0,len(info)):
if compare(info[j],a[i])==True and score_compare(info[j],query[i])==True:
answer+=1
ans.append(answer)
answer=0




return ans
13 changes: 13 additions & 0 deletions 15주차/2146/2146_python_노유빈.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 잘 모르겠다..



# 첫 줄에는 지도의 크기 N(100이하의 자연수)가 주어진다.
# 그 다음 N줄에는 N개의 숫자가 빈칸을 사이에 두고 주어지며, 0은 바다, 1은 육지를 나타낸다.
# 항상 두 개 이상의 섬이 있는 데이터만 입력으로 주어진다.


N = int(input())
map = input()

# 각 섬 별 숫자를 다르게 표기하기
73 changes: 73 additions & 0 deletions 16주차/(P)17677/17677_js_강윤석.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
function solution(str1, str2) {

const [ str1Map, str2Map ] = [str1, str2]
.map(str => get2WordChunks(str))
.map(chunk => getMapOfArr(chunk));

const dividend = getDividend(str1Map, str2Map);
const divisor = getDivisor(str1Map, str2Map);

if(dividend === 0 && divisor === 0) {
return 65536
}

return Math.floor(65536 * (dividend / divisor))
}

function getMapOfArr(strArr) {
const map = new Map();

strArr.forEach(str => {
if(map.has(str) === false) {
map.set(str, 0);
}

map.set(str, map.get(str) + 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 2개씩 자른 영어문자열을 그냥 배열로 저장하고 모두 비교하는데 이렇게 map을 이용해서 같은 영어문자열은 중복해서 저장하지 않고 영어문자열을 key로 영어문자열의 개수는 value로 저장하는 방법도 좋은거 같습니다!

})

return map;
}

function getDividend(str1Map, str2Map) {
let count = 0;

for(const [ k, v ] of str1Map) {
if(str2Map.has(k)) {
count += Math.min(str2Map.get(k), v)
}
}

return count;
}

function getDivisor(str1Map, str2Map) {
const map = new Map(str1Map);

for(const [ k, v ] of str2Map) {
if(map.has(k)) {
map.set(k, Math.max(v, map.get(k)))
} else {
map.set(k, v);
}
}

return Array.from(map.values()).reduce((acc, curr) => acc + curr, 0);
}

function get2WordChunks(str) {
return Array.from(str)
.reduce((acc, curr, index) => {
if(index === str.length - 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

js는 '==' 와 '==='가 다르다는 것을 이번에 찾아보면서 또 배웠네요😊

return acc;
}

acc.push(`${curr}${str[index+1]}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반복문을 대신해서 reduce함수를 사용하고 이부분에서 string을 2개씩 나누는 거군요!

return acc;
}, [])
.filter((chunk) => isAlpha(chunk[0])&&isAlpha(chunk[1]))
.map((ch) => ch.toLowerCase())
}

function isAlpha(ch) {
return (ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z");
}
83 changes: 83 additions & 0 deletions 16주차/(P)81302/81302_js_강윤석.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
function solution(places) {
return places.map((p) => {
const place = p.map((str) => Array.from(str));

console.log(place) //log

for(let row = 0; row < place.length; row++) {
for(let col = 0; col < place[0].length; col++) {
if(place[row][col] !== "P") {
continue;
}

if(isDistanceOK(place, row, col) === false) {
console.log(`Not ok at [${row},${col}]`) //log
return 0;
}
}
}
return 1;
});
}

const manhatan1 = [[0,1], [1,0], [0,-1], [-1,0]];
const manhatan2 = [[1,1], [1,-1], [-1,1], [-1,-1]];
const manhatan2Far = [[0, 2], [2,0], [-2,0], [0,-2]];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맨해튼 거리가 2보다 같거나 작은 경우를 각각 나누어서 정해놓고 코드를 짜니 훨씬 깔끔하고 보기 좋아요😊


function isDistanceOK(places, row, col) {
console.log(`Person at [${row},${col}]`) //log

const manhatan1People = manhatan1.filter(([r, c]) => {
const nr = row + r;
const nc = col + c;

return isPosValid(places, nr, nc) && places[nr][nc] === "P";
})

if(manhatan1People.length > 0) {
return false;
}

const manhatan2People = manhatan2.filter(([r, c]) => {
const nr = row + r;
const nc = col + c;

return isPosValid(places, nr, nc) && places[nr][nc] === "P";
});

if(manhatan2People.length > 0) {
for(const [r, c] of manhatan2People) {
if(places[row][col + c] !== "X" || places[r + row][col] !== "X") {
return false;
}
}
}

const manhatan2FarPeople = manhatan2Far.filter(([r, c]) => {
const nr = row + r;
const nc = col + c;

return isPosValid(places, nr, nc) && places[nr][nc] === "P";
});

if(manhatan2FarPeople.length === 0) {
return true;
}

for(const [r, c] of manhatan2FarPeople) {
if(r === 0 && places[row][col + c/2] !== "X") {
return false;
}

if(c === 0 && places[row + r/2][col] !== "X") {

return false;
}
}

return true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맨해튼 거리가 1과 2인 경우 좌표가 유효한지 확인하고 1인경우는 바로 false를 리턴, 2인 경우는 위에서 정의했던 dx,dy값들을 이용해서 'X'인지 확인하니 코드가 정말 잘 이해됩니다!


function isPosValid(places, row, col) {
return places[row] && places[row][col];
}
Loading