매일 Algorithm

신재원·2023년 3월 22일
0

Algorithm

목록 보기
73/243

백준 2475번 (구현)

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int [] arr = new int [5];
        int sum = 0;
        for(int i = 0 ; i < arr.length; i++){
            arr[i] = in.nextInt();
            // 값의 제곱을 누적해준다.
            sum += arr[i] * arr[i];
        }
        System.out.println(sum % 10);
    }
}

백준 10250번 (구현)

import java.util.Scanner;

public class problem226 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int size = in.nextInt(); // 테스트 갯수

        for (int i = 0; i < size; i++) {
            int a = in.nextInt(); // 층수
            int b = in.nextInt(); // 각층의 방수
            int c = in.nextInt(); // 몇 번째 손님

            if (c % a == 0) { // 손님의 순서와 층수의 배수가 동일한경우
                // 아파트 호 형식에 맞춰, *100
                System.out.println((a * 100) + (c / a));
            } else {
                System.out.println((c % a) * 100 + (c / a) + 1);
            }
        }
    }
}

백준 9086번 (구현)

import java.util.Scanner;

public class problem227 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int t = in.nextInt();

        for (int i = 0; i < t; i++) {
            String st = in.next();

            // 첫번째 문자, 마지막 문자 출력
            System.out.println(st.substring(0, 1)
                    + st.substring(st.length() - 1, st.length()));
        }
    }
}

백준 10886번 (구현)

import java.util.Scanner;

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

        int t = in.nextInt();

        int zero = 0;
        int one = 0;
        for(int i = 0; i < t; i++){
            int n = in.nextInt();
            if(n == 1){
                one++;
            }else{
                zero++;
            }
        }
        if(zero > one){
            System.out.print("Junhee is not cute!");
        }else{
            System.out.print("Junhee is cute!");
        }
    }
}

백준 2953번 (구현)

import java.util.Scanner;

public class problem229 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int max = 0;
        int index = 0;
        for(int i = 0 ; i < 5; i++){
            int total = 0;
            for(int j = 0; j < 4; j++){
                int n = in.nextInt();
                total += n;
                if(max < total){
                    max = total;
                    // 최대값의 순서를 저장
                    index = i + 1;
                }
            }
        }
        System.out.print(index + " " + max);
    }
}

백준 5355번 (구현)

import java.util.Scanner;

public class problem230 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int t = in.nextInt();
        in.nextLine(); // 개행 제거
        for (int i = 0; i < t; i++) {
            String str = in.nextLine();
            String[] arr = str.split(" ");
            // Float 변수 담아준다.
            float num = Float.parseFloat(arr[0]);
            for (int j = 1; j < arr.length; j++) {
                if (arr[j].equals("@")) {
                    num *= 3;
                } else if (arr[j].equals ("%")) {
                    num += 5;
                } else if (arr[j].equals("#")){
                    num -= 7;
                }
            }
            // 소수 2번째 자리까지 포맷
            System.out.println(String.format("%.2f",num));

        }
    }
}

0개의 댓글