Skip to content

Commit 12b9510

Browse files
committed
issue #35 백준 분수찾기 자바
1 parent 79d1eeb commit 12b9510

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

‎src/backjoon/_1193.java‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package backjoon;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
7+
// https://www.acmicpc.net/problem/1193
8+
// 분수찾기
9+
10+
public class _1193 {
11+
public static void main(String[] args) throws IOException {
12+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
13+
// memory 11492 runtime 76
14+
int X = Integer.parseInt(br.readLine());
15+
int line = 0;
16+
int cnt = 0; //칸의 개수
17+
18+
// X가 몇 번째 대각선 위에 있는지 구하기
19+
while (cnt < X) {
20+
line++;
21+
// 대각선별 칸의 개수가 1,3,6,10,...으로 누적합으로 커진다.
22+
cnt += line; //1씩 증가하는 누적합
23+
}
24+
// System.out.println("line: "+line+", cnt: "+cnt);
25+
26+
// 대각선이 홀수일때 분모가 큰 수
27+
if (line % 2 != 0) {
28+
int top = 1 + (cnt - X);
29+
int bottom = line - (cnt - X);
30+
System.out.println(top + "/" + bottom);
31+
}
32+
// 대각선이 짝수일때 분자가 큰 수
33+
else {
34+
int top = line - (cnt - X);
35+
int bottom = 1 + (cnt - X);
36+
System.out.println(top + "/" + bottom);
37+
}
38+
}
39+
}
40+
/*
41+
* input 14 output 2/4
42+
*/

0 commit comments

Comments
 (0)