코딩하는 털보

21.09.08 TIL 본문

Diary/Today I Learned

21.09.08 TIL

이정인 2021. 9. 8. 17:53

클린 코드, 12 창발성

https://rockintuna.tistory.com/191?category=886434

백준 코드 퀴즈

2869번

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

public class Q2869 {
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException {
        String[] nums = reader.readLine().split(" ");
        int up = Integer.parseInt(nums[0]);
        int down = Integer.parseInt(nums[1]);
        int height = Integer.parseInt(nums[2]);
        int day = 0;

        day += (height-up)/(up-down);;
        if ( (height-up)%(up-down) > 0) {
            day += 2;
        } else {
            day += 1;
        }
        System.out.println(day);
    }
}

10250번

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

public class Q10250 {
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException {
        int tests = Integer.parseInt(reader.readLine());

        for (int i = 0; i < tests; i++) {
            String[] test = reader.readLine().split(" ");
            int height = Integer.parseInt(test[0]);
            int weight = Integer.parseInt(test[1]);
            int num = Integer.parseInt(test[2]);
            calc(height, weight, num);
        }
    }

    public static void calc(int height, int weight, int num) {
        int YY;
        int XX;
        if ( num%height == 0 ) {
            YY = height;
            XX = num/height;
        } else {
            YY = num%height;
            XX = num/height + 1;
        }
        if ( XX < 10 ) {
            System.out.println(String.valueOf(YY) + "0" + String.valueOf(XX));
        } else {
            System.out.println(String.valueOf(YY) + String.valueOf(XX));
        }
    }
}

이 문제는 String으로 형변환 하는 부분을 제거하면 수행 시간을 조금 단축시킬 수 있다.

package baekjoon;

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

public class Q10250 {
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException {
        int tests = Integer.parseInt(reader.readLine());

        for (int i = 0; i < tests; i++) {
            String[] test = reader.readLine().split(" ");
            int height = Integer.parseInt(test[0]);
            int weight = Integer.parseInt(test[1]);
            int num = Integer.parseInt(test[2]);
            calc(height, weight, num);
        }
    }

    public static void calc(int height, int weight, int num) {
        int YY;
        int XX;
        if ( num%height == 0 ) {
            YY = height*100;
            XX = num/height;
        } else {
            YY = num%height * 100;
            XX = num/height + 1;
        }
        System.out.println(YY+XX);
    }
}
Comments