24.05.30 목 TIL(Today I Learned)

신민금·2024년 5월 31일
0
post-thumbnail

TIL(Today I Learned)

: 매일 저녁, 하루를 마무리하며 작성 !
: ⭕ 지식 위주, 학습한 것을 노트 정리한다고 생각하고 작성하면서 머리 속 흩어져있는 지식들을 정리 !


알고리즘 코드카타

  • 문제 설명
    두 수를 입력받아 두 수의 최대공약수와 최소공배수를 반환하는 함수, solution을 완성해 보세요. 배열의 맨 앞에 최대공약수, 그다음 최소공배수를 넣어 반환하면 됩니다. 예를 들어 두 수 3, 12의 최대공약수는 3, 최소공배수는 12이므로 solution(3, 12)는 [3, 12]를 반환해야 합니다.
  • 제한사항
    두 수는 1이상 1000000이하의 자연수입니다.
class Solution {
    // 최대공약수 구하는 함수 (유클리드 호제법)
    int func(int x, int y) {
        int num;
        while(y > 0) {
            num = x % y;
            x = y;
            y = num;
        }
        return x;
    }
    
    public int[] solution(int x, int y) {
        int[] answer = new int[2];

        // 큰 수를 n
        if(x < y) {
            int temp = x;
            x = y;
            y = temp;
        }
        
        // 최대공약수
        answer[0] = func(x, y);
        
        // 최소공배수
        answer[1] = x * y / answer[0];
        
        return answer;
    }
}

수준별 학습 챌린지반 2일차

  • 과제 제출
public class RamenProgram {
    public static void main(String args[]) {
        try {
            RamenCook ramenCook = new RamenCook(Integer.parseInt(args[0]));
            new Thread(ramenCook, "A").start();
            new Thread(ramenCook, "B").start();
            new Thread(ramenCook, "C").start();
            new Thread(ramenCook, "D").start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

class RamenCook implements Runnable {
    private int ramenCount;  // 남은 라면 수
    private String[] burners = {"_", "_", "_", "_", "_"};  // 버너 상태를 나타내는 배열

    public RamenCook(int count) {
        ramenCount = count;  // 주어진 라면 수로 초기화
    }

    @Override
    public void run() {
        while (ramenCount > 0) {
            synchronized (this) {
                ramenCount--;  // 라면 수 감소
                System.out.println(Thread.currentThread().getName() + ": " + ramenCount + "개 남음");
            }
            for (int i = 0; i < burners.length; i++) {
                if (!burners[i].equals("_")) continue;  // 버너가 사용 중이면 다음 버너로

                synchronized (this) {
                    // 버너가 사용 가능하면 해당 버너를 점유하고 상태 출력
                    burners[i] = Thread.currentThread().getName();
                    System.out.println(
                        Thread.currentThread().getName()
                        + ": [" + (i + 1) + "]번 버너 ON"
                    );
                    showBurners();
                }

                try {
                    Thread.sleep(2000);  // 요리 시간 시뮬레이션
                } catch (Exception e) {
                    e.printStackTrace();
                }

                synchronized (this) {
                    // 요리가 끝난 후 버너를 해제하고 상태 출력
                    burners[i] = "_";
                    System.out.println(
                        Thread.currentThread().getName()
                        + ": [" + (i + 1) + "]번 버너 OFF"
                    );
                    showBurners();
                }
                break;
            }

            try {
                Thread.sleep(Math.round(1000 * Math.random()));  // 다음 반복 전 랜덤 시간 대기
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private void showBurners() {
        // 현재 모든 버너의 상태를 출력
        String stringToPrint = "";
        for (int i = 0; i < burners.length; i++) {
            stringToPrint += (" " + burners[i]);
        }
        System.out.println(stringToPrint);
    }
}


숙련주차 개인과제 진행

Goal: "회원가입, 로그인 기능이 있는 투두앱 백엔드 서버 만들기"

API 설계

엔티티메서드엔드포인트설명요청 본문 예시응답 예시
UserPOST/users사용자 생성{"username": "test_username", "password": "test_password", "nickname": "test_nickname", "role": "USER"}{"id": 1, "username": "test_username", "password": "test_password", "nickname": "test_nickname", "role": "USER", "createdAt": "2024-05-31T00:00:00"}
UserGET/users/{id}ID로 사용자 조회없음{"id": 1, "username": "test_username", "password": "test_password", "nickname": "test_nickname", "role": "USER", "createdAt": "2024-05-31T00:00:00"}
UserGET/users모든 사용자 조회없음[{"id": 1, "username": "test_username", "password": "test_password", "nickname": "test_nickname", "role": "USER", "createdAt": "2024-05-31T00:00:00"}, ...]
UserDELETE/users/{id}ID로 사용자 삭제없음없음
TodoSchedulerPOST/todoschedulersTodoScheduler 생성{"userId": 1, "title": "test_title", "content": "test_content", "state": false}{"id": 1, "userId": 1, "title": "test_title", "content": "test_content", "state": false, "createdAt": "2024-05-31T00:00:00"}
TodoSchedulerGET/todoschedulers/{id}ID로 TodoScheduler 조회없음{"id": 1, "userId": 1, "title": "test_title", "content": "test_content", "state": false, "createdAt": "2024-05-31T00:00:00"}
TodoSchedulerGET/todoschedulers모든 TodoScheduler 조회없음[{"id": 1, "userId": 1, "title": "test_title", "content": "test_content", "state": false, "createdAt": "2024-05-31T00:00:00"}, ...]
TodoSchedulerDELETE/todoschedulers/{id}ID로 TodoScheduler 삭제없음없음
CommentPOST/commentsComment 생성{"todoSchedulerId": 1, "userId": 1, "content": "test_content"}{"id": 1, "todoSchedulerId": 1, "userId": 1, "content": "test_content", "createdAt": "2024-05-31T00:00:00"}
CommentGET/comments/{id}ID로 Comment 조회없음{"id": 1, "todoSchedulerId": 1, "userId": 1, "content": "test_content", "createdAt": "2024-05-31T00:00:00"}
CommentGET/comments모든 Comment 조회없음[{"id": 1, "todoSchedulerId": 1, "userId": 1, "content": "test_content", "createdAt": "2024-05-31T00:00:00"}, ...]
CommentDELETE/comments/{id}ID로 Comment 삭제없음없음

  • 사족 : 프론트엔드는 만들 필요 없었다,, 근데 다 만드느라 시간이 다 가서,,,ㅠ 재제출 때 이쁘게 오류 잡아서 내겠습니다..
profile
야옹

0개의 댓글