코딩테스트/백준(JAVA)

백준 코딩테스트 1-9-10430 나머지 코딩 문제 java로 푸는 방법

쏠솔랄라 2023. 3. 5. 12:09

 

 

 

백준 코딩테스트 단계별로 풀어보기

1단계 입출력과 사칙연산의 9단계 10430번 문제입니다

 

 

https://www.acmicpc.net/step

 

단계별로 풀어보기

단계별은 @jh05013님이 관리하고 계십니다. 단계제목설명정보총 문제내가 맞은 문제1입출력과 사칙연산입력, 출력과 사칙연산을 연습해 봅시다. Hello World!132조건문if 등의 조건문을 사용해 봅시다

www.acmicpc.net

 

 

 


 

 

 

 

문제
(A+B)%C는 ((A%C) + (B%C))%C 와 같을까?(A×B)%C는 ((A%C) × (B%C))%C 와 같을까?
세 수 A, B, C가 주어졌을 때, 위의 네 가지 값을 구하는 프로그램을 작성하시오.

입력
첫째 줄에 A, B, C가 순서대로 주어진다. (2 ≤ A, B, C ≤ 10000)

출력
첫째 줄에 (A+B)%C, 둘째 줄에 ((A%C) + (B%C))%C, 셋째 줄에 (A×B)%C, 넷째 줄에 ((A%C) × (B%C))%C를 출력한다.

 

 

정답

import java.util.Scanner;

public 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();

 

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);

}

}

 

=> 역시 가장 단순하게 생각해야 하는 단순출력문

 

 


 

 

1-1-2557 https://developernew.tistory.com/41 <- 백준 답지 제출 방법
1-2-1000 https://developernew.tistory.com/42
1-3-1001 https://developernew.tistory.com/43
1-4-10998 https://developernew.tistory.com/44
1-5-1008 https://developernew.tistory.com/45
1-6-10869 https://developernew.tistory.com/46
1-7-10926 https://developernew.tistory.com/47
1-8-18108 https://developernew.tistory.com/48