https://www.acmicpc.net/problem/2839
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if (n % 5 == 0) { //5로 바로 떨어질 때
System.out.println(n / 5);
return;
} else { //5로 나눴을때 나머지 1이상
int count = n / 5;
for (int i = count; i > 0; i--) {
int temp = n - (i * 5);
if (temp % 3 == 0) {
System.out.println(i + (temp / 3));
return;
}
}
}
if (n % 3 == 0) {
System.out.println(n / 3);
} else {
System.out.println(-1);
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
int count = n / 5;
switch (n % 5) {
case 0:
System.out.println(count);
break;
case 1:
case 3:
System.out.println(count + 1);
break;
case 2:
if (count < 2) {
System.out.println(-1);
} else {
System.out.println(count + 2);
}
break;
case 4:
if (count < 1) {
System.out.println(-1);
} else {
System.out.println(count + 2);
}
break;
}
}
}
'💡 Algorithm > 백준' 카테고리의 다른 글
[JAVA] 백준 #10809 - 알파벳 찾기 (0) | 2020.08.21 |
---|---|
[JAVA] 백준 #2675 - 문자열 반복 (0) | 2020.08.21 |
[JAVA ] 백준 #1157- 단어 공부 (0) | 2020.08.20 |
[JAVA] 백준 #2741 - N 찍기 (Scanner,BufferedReader,BufferedWriter) (0) | 2020.06.24 |
[JAVA ] 백준 #15552 - 빠른 A+B (0) | 2020.06.24 |
[JAVA] 백준 #2884 - 알람 시계 (0) | 2020.06.16 |