SW Academy

[CNU SW Academy] 11일차(22.12.15)

narlo 2022. 12. 15. 15:49

어제는 시험이 두개나 있어서 공부하느라 참여를 하지 못했다.

어제 못한 분량은 주말이나 다음주에 채울 예정이다.


 

코딩테스트

지난번에 못풀었던

직선을 이루는 점 찾기(22.12.13)와 큐&스택(22.12.14) 문제를 풀었다.

 

12.13

직선을 이루는 점 찾기

n = int(input())		# 좌표 개수
points = []				# 입력받은 점들을 저장할 list

def findPoints():		# 결과를 찾는 함수
    global points
    result = 0			# 반환값을 저장할 변수

    for i in range(len(points)):	
        hm = dict()		# dict 자료형 이용
        line_x = 1		# x의 변화량이 0인 경우
        x1, y1 = points[i][0], points[i][1]
        for j in range(len(points)):
            x2, y2 = points[j][0], points[j][1]
            if i != j:
                if x1 == x2:
                    line_x += 1
                    continue
                w = (y2 - y1) / (x2 - x1)
                if w in hm:			# dictonary 안에 키 w가 존재한다면
                    hm[w] = hm[w] + 1
                else:				# dictionary 안에 키 w가 존재하지 않는다면
                    hm[w] = 2
                result = max(result, hm[w])
        result = max(result, line_x)
    return result

for i in range(n):
    x, y = map(int, input().split(" "))
    points.append([x, y])

result = findPoints()
print(result)

파이썬의 dict를 이용하여 해결하였다.

지난 번에는 두 점을 계속해서 선택하며 기울기 w와 b를 구해 dict 안에 dict가 있는 구조를 만들어보려고 했으나 실패했다.  

 

하나의 점 (xi, yi)를 기준으로 기울기를 구한 후, 그 max값만 저장해두면 위처럼 복잡한 구조가 아니더라도

해결할 수 있다는 것을 알았다.

 


12.14

스택 & 큐 구현

from collections import deque
s = input().split(" ")
ss = s[0]
n = int(s[1])
deq = deque()

for i in range(n):
    cond = list(map(int, input().split(" ")))
    if ss == 'Stack':
        if cond[0] == 0:
            print(len(deq))
        elif cond[0] == 1:
            print(deq[-1])
        elif cond[0] == 2:
            deq.pop()
        else:
            deq.append(cond[1])
    else:
        if cond[0] == 0:
            print(len(deq))
        elif cond[0] == 1:
            print(deq[0])
        elif cond[0] == 2:
            deq.popleft()
        else:
            deq.append(cond[1])

파이썬의 deque를 이용하여 구현했다.

Stack의 경우 뒤에서 pop, append 연산이 일어나고,

Queue의 경우 앞에서 popleft, 뒤에서 append연산이 일어난다.

 

12.15

토마토

 

from collections import deque
m, n = map(int, input().split(" "))
box = []
q = deque()
for i in range(n):
    box.append(list(map(int, input().split(" "))))
    for j in range(m):
        if box[i][j] == 1:
            q.append((0, i, j))


dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]

while q:
    day, x, y = q.popleft()
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if nx >= 0 and nx < n and ny >= 0 and ny < m and box[nx][ny] == 0:
            box[nx][ny] = 1
            q.append((day+1, nx, ny))

flag = False
for i in range(n):
    if 0 in box[i]:
        flag = True
        print(-1)
        break
if not flag:
    print(day)

bfs를 이용하는 문제이다.

 


프론트엔드 미니 데브코스

가장 먼 노드 문제풀이

class Queue {
    constructor() {
        this.queue = [];
        this.front = 0;
        this.rear = 0;
    }

    enqueue(value) {
        this.queue[this.rear++] = value;
    }

    dequeue() {
        const value = this.queue[this.front];
        delete this.queue[this.front];
        this.front += 1;
        return value;
    }

    isEmpty() {
        return this.rear === this.front
    }

}

function solution(n, edge) {
    const graph = Array.from(Array(n+1), () => []);

    for(const [src, dest] of edge) {
        graph[src].push(dest);
        graph[dest].push(src);
    }

    const distance = Array(n+1).fill(0);
    distance[1] = 1;

    const queue = new Queue()
    queue.enqueue(1);
    while (!queue.isEmpty()) {
        const src = queue.dequeue();
        for(const dest of graph[src]) {
            if (distance[dest] === 0) {
                queue.enqueue(dest);
                distance[dest] = distance[src] + 1;
            }
        }
    }
    const max = Math.max(...distance);
    return distance.filter(item => item === max).length;
}

 


문현수 박사님 - 프로젝트 설계, 구현 특강

네트워크 패킷

IPC(Inter Process Communication)

소켓, 소켓 사이에 어떤 것이 오가는지를 배울 예정

 

Server - Client 간 통신

client가 몇개인지 server에서는 알 수 없다.

=> 규칙을 만들었음

 

server - client 사이에도 Protocol이라는 rule이 존재

 

웹 : HTTP통신

패킷 캡처를 할 줄 알면 통신 과정 중 어디서부터 문제인지를 알 수 있다. 

 

 

'SW Academy' 카테고리의 다른 글

[CNU SW Academy] 13일차(22.12.19)  (0) 2022.12.22
[CNU SW Academy] 12일차(22.12.16)  (0) 2022.12.18
[CNU SW Academy] 9일차(22.12.13.)  (0) 2022.12.13
[CNU SW Academy] 8일차(22.12.12.)  (0) 2022.12.12
[CNU SW Academy] 7일차(22.12.09.)  (0) 2022.12.09