매일 Algorithm

신재원·2023년 3월 18일
0

Algorithm

목록 보기
69/243

백준 1475번 (구현)

import java.util.Scanner;

public class problem210 {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        String st = in.next();

        // 한세트에 0 ~ 9 배열
        int[] arr = new int[10];
        for (int i = 0; i < st.length(); i++) {
            /*
            숫자 형태의 char형을 int로 변환
            (Character.getNumericValue(char ch));
            */
            int count = Character.getNumericValue(st.charAt(i));
            if (count == 6) {
                arr[9]++;
            } else {
                arr[count]++;
            }
        }

        int max = 0;
        // arr[9] 배열 전까지의 max값을 구해준다.
        for (int i = 0; i < 9; i++) {
            max = Math.max(max, arr[i]);
        }

        // 입력값이 9 일경우
        int nine = arr[9] / 2;
        // arr[9] 배열의 홀수일경우 한세트를 더 사야된다.
        if (arr[9] % 2 == 1) nine++;

        max = Math.max(max, nine);

        System.out.print(max);
    }
}

백준 2914번 (구현)

import java.util.Scanner;

public class problem211 {
    public static void main(String[] args) {
    
    	// 간단한 구현문제다.
        
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int m = in.nextInt();

        System.out.print(n * (m-1)+1);


    }
}

백준 2576번 (구현)

import java.util.Scanner;

public class problem212 {
    public static void main(String[] args) {

        // 간단한 구현문제다.

        Scanner in = new Scanner(System.in);


        int sum = 0;
        int min = 100;
        for (int i = 0; i < 7; i++) {
            int n = in.nextInt();
            if (n % 2 == 1) {
                sum += n;
                min = Math.min(min, n);
            }
        }

        if (sum == 0) {
            System.out.print(-1);
        } else {
            System.out.println(sum);
            System.out.println(min);
        }

    }
}

백준 10988번 (구현)

import java.util.Scanner;

public class problem213 {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);


        String str = in.next();
        char ch [] = str.toCharArray();

        char [] reverse = new char[ch.length];
        int index = 0;
        for(int i = ch.length - 1; i >= 0; i--){
            reverse[index] = ch[i];
            index++;
        }


        // 뒤집은 값이랑 같은지 확인
        if(str.equals(String.valueOf(reverse))){
            System.out.print(1);
        }else{
            System.out.print(0);
        }
    }
}

0개의 댓글