[백준 - 2839] 설탕 배달

[백준 - 2839] 설탕 배달

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

package com.example.study.algorithm.baekjoon; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class BaekJoon_2839 { public static void main( String [] args) throws IOException { BufferedReader br = new BufferedReader( new InputStreamReader( System . in )); StringTokenizer st = new StringTokenizer(br.readLine()); int N = Integer. parseInt (st.nextToken()); int sum = - 1 ; sum = find(N); System . out . println (sum); } public static int find( int n) { int temp = n; int count = temp / 5 ; int sum = - 1 ; for ( int i = 0 ; i < = count; i + + ) { temp = temp - 5 * i; temp = temp / 3 ; if (( 3 * temp + 5 * i) = = n) sum = temp + i; temp = n; } return sum; } } Colored by Color Scripter

from http://algorithm-master.tistory.com/148 by ccl(A) rewrite - 2021-12-12 23:01:47