매일 Algorithm

신재원·2023년 4월 1일
0

Algorithm

목록 보기
83/243

백준 1453번 (구현)

import java.util.Scanner;

public class problem262 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int input = in.nextInt();
        boolean[] flag = new boolean[101]; // 배열 크기 할당
        int count = 0;

        for (int i = 1; i <= input; i++) {
            int n = in.nextInt();
            if (flag[n]) count++;
            else flag[n] = true; // 앉았으면 true
        }
        System.out.print(count);
    }
}

백준 1138번 (구현)

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class problem263 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        List<Integer> list = new ArrayList<>();
        int[] arr = new int[n + 1]; // 0번 인덱스를 사용하지 않기위해
        for (int i = 1; i <= n; i++) {
            arr[i] = in.nextInt();
        }
        // arr[1] = 2 arr[2] = 1 arr[3] = 1 arr[4] = 0
        // 4 2 1 3
        for (int i = n; i >= 1; i--) {
            list.add(arr[i], i);
        }
        for (int i : list) {
            System.out.print(i + " ");
        }
    }
}

백준 10768번 (구현)

import java.util.Scanner;

public class problem264 {

    public static void main(String[] args) {

        // 간단한 구현문제이다.
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();

        if(n < 2){
            System.out.print("Before"); // 2월보다 낮을경우
        }else if (n == 2){
            if(m < 18){
                System.out.print("Before");
            }else if(m > 18){
                System.out.print("After");
            }else{
                System.out.print("Special");
            }
        }else{
            System.out.print("After");
        }

    }
}

백준 15963번 (구현)

import java.util.Scanner;

public class problem265 {

    public static void main(String[] args) {

        // 간단한 구현문제이다.
        Scanner in = new Scanner(System.in);
        long n = in.nextLong(); // 10자리 정수가 넘어가기 때문에 long타입
        long m = in.nextLong();

        if(n == m){
            System.out.print("1");
        }else{
            System.out.print("0");
        }


    }
}

0개의 댓글