forked from GreatAlgorithm-Study/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
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;
}
}