Skip to content

Commit

Permalink
CT_271
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-Good committed Oct 5, 2024
1 parent 44ca794 commit b0943f6
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions BOJ/Java/src/S3/Boj_1735_분수합.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package S3;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

public class Boj_1735_분수합 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine());
int A = Integer.parseInt(st.nextToken());
int B = Integer.parseInt(st.nextToken());

st = new StringTokenizer(br.readLine());
int C = Integer.parseInt(st.nextToken());
int D = Integer.parseInt(st.nextToken());

A = A * D + C * B;
B = B * D;

C = A;
D = B;

while (D > 0) {
int temp = D;
D = C % D;
C = temp;
}

sb.append(A / C).append(' ').append(B / C);
bw.write(sb.toString());
bw.flush();
}
}

0 comments on commit b0943f6

Please sign in to comment.