백준/JAVA

[백준/JAVA] 단계별로 풀어보기(7단계) 기본 수학 1

누룽지맛치킨 2023. 2. 6. 15:37

문제 1712) 손익분기점

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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int A = Integer.parseInt(st.nextToken());
        int B = Integer.parseInt(st.nextToken());
        int C = Integer.parseInt(st.nextToken());

        int profit;
        if(C-B<=0) {
            profit = -1;
        }
        else{
            profit = A/(C-B) + 1;
        }
        System.out.println(profit);
    }
}

문제 2292) 벌집

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

public class Main {
    public static void main(String[] arg) throws IOException{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int num = Integer.parseInt(br.readLine());
            num = num - 1;
            int count = 1;
            int temp=6;
            int i = 12;
            while(num>0) {
                count++;
                if(num<=temp) {
                    break;
                }
                temp+=i;
                i+=6;
            }
            System.out.println(count);

    }
}

문제 1193) 분수찾기

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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int X = Integer.parseInt(br.readLine());
        int i=1;
        int t;
        StringBuilder sb = new StringBuilder();
        while(true) {
            t= i*(i+1)/2;
            if(X<=t) {
                i+=1;
                break;
            }
            i++;
        }
        if(i%2==0) {
            int mom = i-1-(t-X);
            int son = i-mom;
            sb.append(son).append("/").append(mom);
        }
        else {
            int son = i-1-(t-X);
            int mom = i-son;
            sb.append(son).append("/").append(mom);
        }
        System.out.println(sb);

    }
}

문제 2869) 달팽이는 올라가고 싶다

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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int A = Integer.parseInt(st.nextToken());
        int B = Integer.parseInt(st.nextToken());
        int V = Integer.parseInt(st.nextToken());

        int move = A-B;
        int dest = V-A;

        if(dest%move==0) {
            System.out.println(dest/move+1);
        }
        else {
            System.out.println(dest/move+2);
        }
    }
}

문제 10250) ACM 호텔

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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(br.readLine());
        StringTokenizer st;
        StringBuilder sb = new StringBuilder();
        int H,W,N;
        for(int i=0; i<T;i++) {
            st = new StringTokenizer(br.readLine());
            H = Integer.parseInt(st.nextToken());
            W = Integer.parseInt(st.nextToken());
            N = Integer.parseInt(st.nextToken());
            if(N%H==0) {
                sb.append(H).append(String.format("%02d", N/H)).append("\n");
            }
            else {
                sb.append(N%H).append(String.format("%02d", N/H+1)).append("\n");
            }
        }
        System.out.print(sb);
    }
}

문제 2775) 부녀회장이 될테야

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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(br.readLine());
        int k, n;
        StringBuilder sb = new StringBuilder();
        for(int i =0;i<T;i++) {
            k = Integer.parseInt(br.readLine());
            n = Integer.parseInt(br.readLine());
            sb.append(fun(k,n)).append("\n");
        }
        System.out.print(sb);
    }

    private static int fun(int k, int n ) {
        int people = 0;
        if(k==0) {
            return n;
        }
        else {
            for(int i=1;i<=n;i++) {
                people += fun(k-1,i);
            }
            return people;
        }
    }
}

문제 2839) 설탕 배달

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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        if(N%5==0) {
            System.out.println(N/5);
        }
        else if(N%5==1 && N >5) {
            N-=6;
            System.out.println(N/5 +2);
        }
        else if(N%5==2 && N>10) {
            N-=12;
            System.out.println(N/5+4);
        }
        else if(N%5==3) {
            N-=3;
            System.out.println(N/5+1);
        }
        else if(N%5==4 && N>5) {
            N-=9;
            System.out.println(N/5+3);
        }
        else {
            System.out.println("-1");
        }
    }
}

문제 10757) 큰 수 A+B

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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        String A = st.nextToken();
        String B = st.nextToken();
        StringBuilder sb = new StringBuilder();
        int temp = 0;
        int num = 0;
        int i = (A.length() < B.length()) ? A.length() : B.length();
        for(int j =  0; j<i;j++) {
            num = (int)A.charAt(A.length()-1-j) -'0' + (int)B.charAt(B.length()-1-j)-'0' + temp;
            temp = num/10;
            num = num%10;
            sb.append(num);
        }
        if(A.length()>B.length()) {
            for(int j = i ; j<A.length();j++) {
                num = (int)A.charAt(A.length()-1-j)-'0' + temp;
                temp = num/10;
                num = num%10;
                sb.append(num);
            }
        }
        else {
            for(int j = i ; j<B.length();j++) {
                num = (int)B.charAt(B.length()-1-j)-'0' + temp;
                temp = num/10;
                num = num%10;
                sb.append(num);
            }
        }
        if(temp==1) {
            sb.append(1);
        }
        sb.reverse();
        System.out.println(sb);
    }
}