반응형
https://www.acmicpc.net/problem/14490
입력값에 대한 전처리를 간단하게 한 후, 최대공약수를 구해서 답을 출력해주는 문제이다.
문제 및 입출력
코드
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
// 전처리
String[] input = sc.nextLine().split(":");
int a = Integer.parseInt(input[0]);
int b = Integer.parseInt(input[1]);
int first = Math.max(a, b);
int second = Math.min(a, b);
// 최대공약수 구하기
while(second!=0)
{
int temp = first;
first = second;
second = temp%second;
}
System.out.println(a/first + ":" + b/first);
sc.close();
}
}
반응형
'[ 다먹살 ] > - Coding' 카테고리의 다른 글
[백준] 1531 투명 (0) | 2022.03.31 |
---|---|
[백준] 11441 합 구하기 (0) | 2022.03.29 |
[백준] 2822 점수계산 (0) | 2022.03.25 |
[백준] 9656 돌 게임2 (0) | 2022.03.23 |
[백준] 10988 팰린드롬인지 확인하기 (0) | 2022.03.18 |
댓글