[ 다먹살 ]/- Coding
[백준] 14490 백대열
엉망으로살기
2022. 3. 28. 09:01
반응형
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();
}
}
반응형