-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_1193.java
More file actions
42 lines (37 loc) ยท 1.08 KB
/
_1193.java
File metadata and controls
42 lines (37 loc) ยท 1.08 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
package backjoon;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
// https://www.acmicpc.net/problem/1193
// ๋ถ์์ฐพ๊ธฐ
public class _1193 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// memory 11492 runtime 76
int X = Integer.parseInt(br.readLine());
int line = 0;
int cnt = 0; //์นธ์ ๊ฐ์
// X๊ฐ ๋ช ๋ฒ์งธ ๋๊ฐ์ ์์ ์๋์ง ๊ตฌํ๊ธฐ
while (cnt < X) {
line++;
// ๋๊ฐ์ ๋ณ ์นธ์ ๊ฐ์๊ฐ 1,3,6,10,...์ผ๋ก ๋์ ํฉ์ผ๋ก ์ปค์ง๋ค.
cnt += line; //1์ฉ ์ฆ๊ฐํ๋ ๋์ ํฉ
}
// System.out.println("line: "+line+", cnt: "+cnt);
// ๋๊ฐ์ ์ด ํ์์ผ๋ ๋ถ๋ชจ๊ฐ ํฐ ์
if (line % 2 != 0) {
int top = 1 + (cnt - X);
int bottom = line - (cnt - X);
System.out.println(top + "/" + bottom);
}
// ๋๊ฐ์ ์ด ์ง์์ผ๋ ๋ถ์๊ฐ ํฐ ์
else {
int top = line - (cnt - X);
int bottom = 1 + (cnt - X);
System.out.println(top + "/" + bottom);
}
}
}
/*
* input 14 output 2/4
*/