-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHW_250135.java
More file actions
47 lines (37 loc) ยท 1.27 KB
/
HW_250135.java
File metadata and controls
47 lines (37 loc) ยท 1.27 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
43
44
45
46
47
class HW_250135 {
public int solution(int h1, int m1, int s1, int h2, int m2, int s2) {
int cnt = 0;
double start = h1 * 3600 + m1 * 60 + s1;
double end = h2 * 3600 + m2 * 60 + s2;
int halfDay = 12 * 3600;
if (start == 0 || start == halfDay)
cnt++;
while (start < end) {
double h = (start / 120) % 360; // ์์นจ
double m = (start / 10) % 360; // ๋ถ์นจ
double s = (start * 6) % 360; // ์ด์นจ
// ๋ค์ ์๊ฐ์ ๊ฐ๋ ๊ณ์ฐ
double nextH = ((start + 1) / 120) % 360;
double nextM = ((start + 1) / 10) % 360;
double nextS = ((start + 1) * 6) % 360;
// 360๋ -> 0๋
if (nextH == 0.0) {
nextH = 360.0;
}
if (nextM == 0.0){
nextM = 360.0;
}
if (nextS == 0.0) {
nextS = 360.0;
}
if (s < h && nextH <= nextS) // ์ด์นจ == ์์นจ
cnt++;
if (s < m && nextM <= nextS) // ์ด์นจ==๋ถ์นจ
cnt++;
if (nextH == nextS && nextM == nextS) // ์์นจ,๋ถ์นจ==์ด์นจ
cnt--;
start++;
}
return cnt;
}
}