백준 14490 c++

magicdrill·2024년 7월 25일
0

백준 문제풀이

목록 보기
402/654

백준 14490 c++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void input_num(int* N, int* M)
{
	char no;

	cin >> *N >> no >> *M;

	return;
}

void find_answer(int N, int M)
{
	//cout << N << M;
	int gcd;
	int n, m, temp;
	if (N > M)
	{
		n = N;
		m = M;
	}
	else
	{
		n = M;
		m = N;
	}
	while (1)
	{
		temp = n;
		n = m;
		m = temp % m;
		if (m == 0)
		{
			break;
		}
	}
	gcd = n;

	cout << N/gcd <<":"<< M/gcd << "\n";

	return;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int N, M;

	input_num(&N, &M);
	find_answer(N, M);

	return 0;
}

0개의 댓글