기본 수학1 [Java]

sua·2022년 9월 23일
0
post-thumbnail

1712번 손익분기점

문제


풀이

import java.util.Scanner;

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

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    if(b >= c){ // 1대를 만드는 금액이 1대를 파는 금액보다 크면 안됨
        System.out.println("-1");
    }
    else{
       System.out.println(a / (c - b) + 1);
    }
  }
}



2292번 벌집

문제



풀이

import java.util.Scanner; 

public class Main { 	
    public static void main(String[] args) {			
        Scanner sc = new Scanner(System.in);		
        
        int n = sc.nextInt();		
        int max = 1;
        int d = 6;
        int answer = 1;		
        
        for(int i = 0; i < n; i++) {			
            if(max >= n) {				
                break;			
            }			
            max += d; 			
            d += 6; // 6의 배수씩 커짐			
            answer++;		
        }		
        System.out.println(answer);
        
        sc.close();
    }
}



1193번 분수찾기

문제



풀이

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int a = 0;
        int r = 0;
        
        for(int i = 1; a < n; i++) {
            a += i;
            r += 1;
        }
        
        int d = a - n;  // 차이를 계산해서 몇번째인지 계산하기 위함
        
        if(r % 2 == 0) { // 짝수인 경우 위에서 아래로 이동
            System.out.print((r - d) + "/" + (d + 1));
        } else { // 홀수인 경우 아래에서 위로 이동
            System.out.print((d + 1) + "/" + (r - d));
        }
        
        sc.close();
    }
}



2869번 달팽이는 올라가고 싶다

문제


풀이

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

public class Main {
    public static void main(String[] args) throws Exception {
        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 day = 1;
        
        v -= a;
        day += v / (a - b);

        if(v % (a - b) > 0) {
            day++;
        }
        System.out.println(day);
    }
}



10250번 ACM 호텔

문제



풀이

import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int t = sc.nextInt();
        
        for(int i  = 0; i < t; i++) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            int n = sc.nextInt();
            int a = (n / h) + 1;
            int b = n % h;
            if(n % h == 0) {
                a = n / h;
                b = h;
            }
            System.out.println(b * 100 + a);
        }
        
        sc.close();
    }
}



2775번 부녀회장이 될테야

문제


풀이

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int t = sc.nextInt();
		int k;
        int n;
        
		for(int i = 0; i < t; i++) {	
			k = sc.nextInt();
			n = sc.nextInt();
			int[] floor = new int[n];
			
			for(int j = 0; j <= k; j++) {	
				for(int m = 0; m < n; m++) { 
					if(j == 0) {
						if(m == 0) {
							floor[m] = 1;
						}
						else {
							floor[m] = m + 1;
						}
					}
					else {
						if(m > 0) {
							floor[m] = floor[m] + floor[m - 1];
						}
					}
				}
			}
			System.out.println(floor[n - 1]);
		}
        
        sc.close();
	}
}   



2839번 설탕 배달

문제


풀이

import java.util.Scanner;

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

        int n = sc.nextInt();
        int a = 0;
        int b = 0;

        while(n % 5 != 0 && n > 0) {
            n -= 3;
            b++;
        }
        a = n / 5;
        n = n % 5;

        if(n < 0) {
            System.out.println(-1);
        }
        else {
            System.out.println(a + b);
        }
        
        sc.close();
    }

}



10757번 큰 수 A+B

문제


풀이

import java.util.*;
import java.math.BigInteger;

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

        BigInteger a = sc.nextBigInteger();
        BigInteger b = sc.nextBigInteger();
        
        System.out.println(a.add(b));
        
        sc.close();
    }
}
profile
가보자고

0개의 댓글