백준 1312

hong030·2023년 3월 2일
0

*실버 5단계 문제

풀이)
나눗셈의 원리를 알면 풀 수 있다.

소수점 1번자리는 (A를 B로 나눈 나머지) x 10 을 B로 나눈 몫
소수점 2번자리는 (1번자리를 만들 때 남은 나머지) x 10 을 B로 나눈 몫
소수점 3번자리는 (2번자리를 만들 때 남은 나머지) x 10 을 B로 나눈 몫
...
이를 이용해 코드를 짠다.

내 코드)

import java.io.*;

public class Backjoon1312 {
	public static void main(String[]args)throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String input[]=bf.readLine().split(" ");
		int A = Integer.parseInt(input[0]);
		int B = Integer.parseInt(input[1]);
		int N = Integer.parseInt(input[2]);
		int temp = A%B;
		int result = 0;
		for(int i=0;i<N;i++) {
			result = temp*10/B;
			temp = temp*10%B;
		}
		System.out.println(result);
		bf.close();
	}
}

profile
자바 주력, 프론트 공부 중인 초보 개발자. / https://github.com/hongjaewonP

0개의 댓글