매일 Algorithm

신재원·2023년 3월 19일
0

Algorithm

목록 보기
70/243

백준 1100번 (구현)

import java.util.Scanner;

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

        Scanner in = new Scanner(System.in);


        // (0,0)이 하얀칸임으로, 행 열을 더해서 짝수면은 하얀칸이다.
        int count = 0;
        for(int i = 0; i < 8; i++){
            String st = in.next();
            for(int j = 0; j < 8; j++){
                if(st.charAt(j) == 'F' && (i+j) % 2 == 0){
                    count++;
                }
            }
        }
        System.out.print(count);
    }
}

백준 2754번 (구현)

import java.util.Scanner;

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

        // 간단한 구현문제다.

        Scanner in = new Scanner(System.in);
        String st = in.next();
        double score = 0.0;

        switch(st){
            case "A+":
                score = 4.3;
                break;
            case "A0":
                score = 4.0;
                break;
            case "A-":
                score = 3.7;
                break;
            case "B+":
                score = 3.3;
                break;
            case "B0":
                score = 3.0;
                break;
            case "B-":
                score = 2.7;
                break;
            case "C+":
                score = 2.3;
                break;
            case "C0":
                score = 2.0;
                break;
            case "C-":
                score = 1.7;
                break;
            case "D+":
                score = 1.3;
                break;
            case "D0":
                score = 1.0;
                break;
            case "D-":
                score = 0.7;
                break;
            case "F":
                score = 0.0;
                break;
        }
        System.out.print(score);
    }
}

백준 2875번 (구현)

import java.util.Scanner;

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


        Scanner in = new Scanner(System.in);

        int n = in.nextInt(); // 여학생
        int m = in.nextInt(); // 남학생
        int k = in.nextInt(); // 인턴십으로 빠질 학생

        int count = 0;

        // k명이 인턴으로 빠지게됨으로, 남학생과 여학생을 
        // 더한수가 크거나 같아야 팀을 꾸릴수있다.
        while(n >= 2 && m >=1 && n+m >= k+3){
            n-=2;
            m-=1;
            count++;
        }

        System.out.print(count);
    }
}

백준 2476번 (구현)

import java.util.Scanner;

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

        // 간단한 구현문제다.
        Scanner in = new Scanner(System.in);

        int size = in.nextInt();
        int max  = 0;
        for (int i = 0; i < size; i++) {
            int total = 0;
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();

            // 주사위 눈이 다 같을 경우
            if (a == b && b == c) {
                total = 10000 + (a * 1000);
            }
            // 주사위 눈이 다 다를 경우
            else if (a != b && a != c && b != c) {
                total = Math.max(a, Math.max(b, c)) * 100;
            } else {
                // 주사위 눈 2개가 같을경우
                if (a == b) {
                    total = 1000 + (a * 100);
                } else if (b == c) {
                    total = 1000 + (b * 100);
                } else {
                    total = 1000 + (c * 100);
                }
            }
            if(total > max){
                max = total;
            }
        }
        System.out.print(max);

    }
}

백준 1159번 (구현)

import java.util.Scanner;

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


        Scanner in = new Scanner(System.in);

        int size = in.nextInt();

        int[] arr = new int[26];
        boolean flag = false;
        for (int i = 0; i < size; i++) {
            String str = in.next();

            // 첫 글자만 검사
            char n = str.charAt(0);
            arr[n - 'a']++;
            if (arr[n - 'a'] == 5) {
                flag = true;
            }

        }
        // flag가 true로 바인딩 된거면 arr배열중 첫 글자가 같은 
        // 5명의 선수가 있다는것이다.
        // 첫 글자가 같은 선수가 5명인지 검증
        if (flag) {
            for (int i = 0; i < arr.length; i++) {
                if (arr[i] >= 5) {
                    System.out.print((char) (i + 'a'));
                }
            }
        } else {
            System.out.print("PREDAJA");
        }
    }
}



0개의 댓글