[2024 동계 모각코]

[2024 동계 모각코] 2회차 개인 목표 및 결과

multipotentialite1 2025. 1. 7. 14:27

일시 : 2025.01.07 14:00 ~ 17:00

 

[2회차 목표]

- JAVA를 활용한 배열, 연결리스트 학습, 그리디 알고리즘, 누적합 학습

 

[2회차 결과]

- 배열, 연결리스트, 그리디 알고리즘, 누적합에 대하여 학습하였습니다.

 

import java.util.Scanner;

public class P11047_동전0 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();

        int [] coin = new int [N]; // 배열 정의

        for (int i = 0; i < N; i++) { // 반복문을 통한 배열 입력값 받기
            coin[i] = sc.nextInt();
        }

        int cnt = 0; // 동전의 개수를 세기 위한 변수 지정

        for (int i = N - 1; i >= 0; i--) { // 큰 수부터 비교하기 위해 i = N - 1부터 시작
            // i가 처음 값이 될 때까지 i를 1만큼 감소시킬 때
            if (K / coin[i] > 0) {
            // K / coin[i] => 몫이 0보다 클 때가 정답이 되는 것이고 그 때의 몫을 cnt에 저장
                cnt += K / coin[i];
            //
                K = K - (K / coin[i] * coin[i]);
            }
        }
        System.out.println(cnt);
    }
}

 

package DataStructure;

public class LinkedList {
    public Node head;
    public Node tail;
}

 

package DataStructure;

public class Node {
    public Node prev;
    public Node next;
    public int value;

    public Node(int value) {
        this.value = value;
    }
}

 

package DataStructure;

public class UseLinkedList {
    public static void main(String[] args) {
        LinkedList list = new LinkedList();

        Node first = new Node(1);

        list.head = first;
        list.tail = first;

        Node now = list.head;

        for (int i = 0; i < 5; i++) { // 데이터 삽입
            now.next = new Node(now.value + 1);
            now = now.next;
            list.tail = now;
        }

    }
}

 

import java.util.Scanner;

public class P11659_구간합구하기4 {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        int [] num = new int[N+1];

        for (int i = 1; i <= N; i++) {
            num[i] = sc.nextInt();
        }

        for (int k = 1; k <= M; k++) {
            int i = sc.nextInt();
            int j = sc.nextInt();
            int sum = 0;
            for (int t = i; t <= j; t++) {
                sum += num[t];
            }
            System.out.println(sum);
        }
    }
}