반응형
문제
문제 풀이
두 분수를 더하고, 최소공약수를 구해주면 된다.
코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include <iostream>
using namespace std;
int gcd(int a, int b)
{
int r;
while (b != 0)
{
r = a % b;
a = b;
b = r;
}
return a;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a, s, d, f;
cin >> a >> s >> d >> f;
a *= f;
d *= s;
a += d;
s *= f;
int GCD = gcd(a, s);
cout << a / GCD << ' ' << s / GCD << endl;
}
|
cs |
반응형
'코딩 > 문제풀이-백준' 카테고리의 다른 글
백준 2805 - 나무 자르기 (C++) (0) | 2021.05.07 |
---|---|
백준 16234번 - 인구 이동 (C++) (0) | 2021.05.07 |
백준 1584번 - 게임 (C++) (0) | 2021.05.05 |
백준 1715번 - 카드 정렬하기 (C++) (0) | 2021.04.27 |
백준 14503번 - 로봇 청소기 (C++) (0) | 2021.04.09 |
댓글