매일 Algorithm

신재원·2023년 3월 31일
0

Algorithm

목록 보기
81/243

백준 25314번 (구현)

import java.util.Scanner;

public class problem254 {

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

        int n = in.nextInt();


        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            if (i % 4 == 0) {
                sb.append("long").append(" ");
            }
        }

        System.out.print(sb.toString() + "int");
    }
}

백준 1748번 (구현)

import java.util.Scanner;

public class problem255 {

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

        int n = in.nextInt();
        int plus = 1; // 자릿수 1부터 시작
        int div = 10;

        int count = 0;
        for (int i = 1; i <= n; i++) {
            // 10 100 1000
            if (i % div == 0) {
                plus++; // 10 = 자릿수 2
                div *= 10; // 자릿수 증가
            }
            count += plus;
        }
        System.out.println(count);
    }
}

백준 7567번 (구현)

import java.util.Scanner;
import java.util.Stack;

public class problem256 {

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

        String[] s = in.next().split("");
        Stack<String> st = new Stack<>();

        int result = 0;

        for (String str : s) {
            if (st.isEmpty()) {
                st.add(str);
                result += 10; // 초기 높이
            } else {
                if (st.peek().equals(str)) {
                    // st 스택의 맨 위의 값이 입력된 문자랑 같을경우
                    result += 5;
                } else {
                    result += 10;
                }
                st.add(str);
            }
        }
        System.out.print(result);

    }
}

백준 2460번 (구현)

import java.util.Scanner;

public class problem257 {

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

        int max = 0;
        int sum = 0;
        for (int i = 0; i < 10; i++) {
            int n = in.nextInt();
            int m = in.nextInt();

            sum += m - n; // 내린사람 탄사람 값 계산
            if (sum > max) {
                max = sum;
            }

        }
        System.out.print(max);
    }
}

0개의 댓글