매일 Algorithm

신재원·2023년 6월 20일
0

Algorithm

목록 보기
149/243

백준 16395번

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class problem480 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = 
        		new BufferedReader(new InputStreamReader(System.in));

        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]); // n번째 행
        int k = Integer.parseInt(input[1]);


        int[][] arr = new int[n + 1][n + 1];

        arr[1][1] = 1; // 초기값 설정


        // n이 3일 경우
        //  121  arr[3][2] = arr[2][1] + arr[2][2]
        //  11
        //  1 = arr[1][1]
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
            }
        }
        System.out.println(arr[n][k]);
    }
}

백준 14912번

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class problem481 {
    public static void main(String[] args) throws IOException {
        BufferedReader br =
                new BufferedReader(new InputStreamReader(System.in));

        String[] input = br.readLine().split(" ");
        int num = Integer.parseInt(input[0]);
        int find = Integer.parseInt(input[1]);

        int count = 0;
        for (int i = 1; i <= num; i++) {
            int temp = i; // 11같은 경우를 위해 변수 할당

            while (temp > 0) {
                // 모듈 연산한 수가 find랑 같을경우
                if (temp % 10 == find) {
                    count++;
                }
                temp /= 10;
            }
        }
        System.out.println(count);
    }
}

0개의 댓글