-
[java]백준 설탕 배달 2839번알고리즘 문제풀이/백준(자바) 2023. 4. 24. 23:36
코드
import java.util.Scanner; public class BOJ_2839 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int s =in.nextInt(); int q=0;//설탕 봉지 수 while (s>=0) { if (s%5==0) {//s가5배수 이면 q+=s/5; System.out.println(q);//설탕 봉지 수 break; }else{//s가3배수 이면 s-=3; q+=1; } }if(!(s>=0)){//s>=0 아니면 System.out.println(-1); } in.close(); } }
링크
https://www.acmicpc.net/problem/2839
'알고리즘 문제풀이 > 백준(자바)' 카테고리의 다른 글
[java]백준 접미사 배열 11656번 (0) 2023.04.26 [java]백준 평균 점수 10039번 (0) 2023.04.25 [java]백준 돌 게임 2 9656번 (0) 2023.04.23 [java]백준 돌 게임 9655번 (0) 2023.04.23 [java]백준 크냐? 4101번 (0) 2023.04.22