반응형
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a, b, c;
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
while(a < 2 || b < 2 || c < 2 || a > 10000 || b > 10000 || c > 10000){
System.out.println("a, b, c의 값은 2 이상 10000이하여야 합니다.");
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
}
System.out.println((a+b)%c);
System.out.println(((a%c)+(b%c))%c);
System.out.println((a*b)%c);
System.out.println(((a%c)*(b%c))%c);
sc.close();
}
}
문제를 푼 후에 다른 분들의 풀이 방식을 봤는데 2<= a, b, c <= 10000 조건을 따로 체크하지 않고 그냥 숫자 입력 후 바로 출력하게 하는 방식이 많았다. 조건 확인을 굳이 할 필요는 없는 듯 싶다..
반응형
'알고리즘 > 백준' 카테고리의 다른 글
[백준] 11382 - 꼬마 정민 (0) | 2024.01.20 |
---|---|
[백준] 2588 - 곱셈 (0) | 2024.01.19 |
[백준] 18108 - 1998년생인 내가 태국에서는 2541년생?! (0) | 2024.01.17 |
[백준] 10926 - ??! (0) | 2024.01.16 |
[백준] 10869 - 사칙연산 (0) | 2024.01.16 |