-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJY_250135.java
More file actions
46 lines (40 loc) Β· 1.49 KB
/
JY_250135.java
File metadata and controls
46 lines (40 loc) Β· 1.49 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
class Solution {
public int solution(int h1, int m1, int s1, int h2, int m2, int s2) {
int answer = 0;
// μ΄μκ°μΌλ‘ λ³ν
double st = changeSec(h1, m1, s1);
double et = changeSec(h2, m2, s2);
// μ μ€, μμ μΌλ μΉ΄μ΄νΈ
int half = 12 * 3600;
if(st == 0 || st == half) answer++;
while(st < et) {
// νμ¬ κ°λ κ³μ°
// μ΄μΉ¨ -> 1μ΄μ 6λ (360λ/60μ΄)
// λΆμΉ¨ -> 1μ΄μ 1/10λ (6λ / 60)
// μμΉ¨ -> 1μ΄μ 1/120λ (6λ / 60*12)
double h = (st / 120) % 360;
double m = (st / 10) % 360;
double s = (st * 6) % 360;
// λ€μ κ°λ
// 0λκ° λλ€λ κ²μ 360λμ κ°μ
double nh = reAngle(((st+1) / 120) % 360);
double nm = reAngle(((st+1) / 10) % 360);
double ns = reAngle(((st+1) * 6) % 360);
// μ΄μΉ¨ == μμΉ¨
if(s < h && nh <= ns) answer++;
// μ΄μΉ¨ == λΆμΉ¨
if(s < m && nm <= ns) answer++;
// μμΉ¨, λΆμΉ¨μ΄ λͺ¨λ κ²ΉμΉ λ
if(nh == ns && nm == ns) answer--;
st++;
}
return answer;
}
public static double changeSec(int h, int m, int s) {
return (double) (h*3600 + m*60 + s);
}
public static double reAngle(double a){
if(a == 0.0) return 360.0;
return a;
}
}