Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 우선순위 큐
- Unreal Engine 5
- 정렬
- XR Interaction Toolkit
- 백준
- 그리디 알고리즘
- 유니온 파인드
- DFS
- 스택
- 구현
- 투 포인터
- 백트래킹
- BFS
- 자료구조
- 브루트포스
- 시뮬레이션
- 누적 합
- c++
- 수학
- VR
- 문자열
- 유니티
- 트리
- ue5
- Team Fortress 2
- 그래프
- 다익스트라
- 다이나믹 프로그래밍
- 알고리즘
- 재귀
Archives
- Today
- Total
1일1알
백준 1735번 분수 합 C++ 본문
https://www.acmicpc.net/problem/1735
1735번: 분수 합
첫째 줄과 둘째 줄에, 각 분수의 분자와 분모를 뜻하는 두 개의 자연수가 순서대로 주어진다. 입력되는 네 자연수는 모두 30,000 이하이다.
www.acmicpc.net
유클리드 알고리즘을 이용해서 최대공약수를 구해서 기약분수를 구한다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int getGcd(int a, int b) {
if (b == 0) return a;
return getGcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int a1, b1, a2, b2;
cin >> a1 >> b1;
cin >> a2 >> b2;
int numerator1 = a1 * b2;
int numerator2 = a2 * b1;
int numerator = numerator1 + numerator2;
int denominator = b1 * b2;
int gcd = getGcd(numerator, denominator);
cout << numerator / gcd << " " << denominator / gcd;
}
'알고리즘' 카테고리의 다른 글
백준 1911번 흙길 보수하기 C++ (0) | 2023.02.08 |
---|---|
백준 2258번 정육점 C++ (0) | 2023.02.07 |
백준 14494번 다이나믹이 뭐에요? C++ (0) | 2023.02.05 |
백준 13901번 로봇 C++ (0) | 2023.02.04 |
백준 16936번 나3곱2 C++ (0) | 2023.02.03 |