Skip to content

Commit

Permalink
이슈 #391에서 솔루션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 26, 2024
1 parent efe5850 commit 5e7275f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Programmers/분수의_덧셈.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int gcd(int a, int b) {
while (b != 0) {
int temp = a % b;
a = b;
b = temp;
}
return a;
}

vector<int> solution(int numer1, int denom1, int numer2, int denom2) {
int numerator = numer1 * denom2 + numer2 * denom1;
int denominator = denom1 * denom2;

int common = gcd(numerator, denominator);
numerator /= common;
denominator /= common;

return {numerator, denominator};
}

0 comments on commit 5e7275f

Please sign in to comment.