매일 Algorithm

신재원·2023년 6월 13일
0

Algorithm

목록 보기
143/243

백준 10808번

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

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

        String input = br.readLine();
        int[] arr = new int[26];

        for (char ch : input.toCharArray()) {
            // index 값 증가
            arr[ch - 'a']++;
        }
        for (int result : arr) {
            System.out.print(result + " ");
        }
    }
}

백준 10824번

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

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

        String[] input = br.readLine().split(" ");

        StringBuilder result = new StringBuilder();
        Long ab = Long.parseLong(input[0] + input[1]); // ab 붙이기
        Long cd = Long.parseLong(input[2] + input[3]); // cd 붙이기

        result.append(ab + cd);

        System.out.println(result.toString());
    }
}

백준 2309번

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

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

        int[] numbers = new int[9];
        int total = 0;
        int delete1 = 0; // 제거해야할 난쟁이1
        int delete2 = 0; // 제거해야할 난쟁이2
        for (int i = 0; i < 9; i++) {
            numbers[i] = Integer.parseInt(br.readLine());
            total += numbers[i];
        }

        Arrays.sort(numbers);

        // 140에서 제거 난쟁이는 25, 15 입니다.
        for (int i = 0; i < 9; i++) {
            for (int j = i + 1; j < 9; j++) {
                // 제거해야할 난쟁이 탐색
                if (total - numbers[i] - numbers[j] == 100) {
                    delete1 = i;
                    delete2 = j;
                }
            }
        }

        for (int i = 0; i < 9; i++) {
            if (i == delete1 || i == delete2) continue;
            System.out.println(numbers[i]);
        }
    }
}

0개의 댓글