Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f73dfc8

Browse files
이지영: [PG] 아날로그 시계_241205
1 parent 8f0d62b commit f73dfc8

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

‎Programmers/Level2/JY_250135.java‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
class Solution {
2+
public int solution(int h1, int m1, int s1, int h2, int m2, int s2) {
3+
int answer = 0;
4+
// 초시간으로 변환
5+
double st = changeSec(h1, m1, s1);
6+
double et = changeSec(h2, m2, s2);
7+
8+
// 정오, 자정일때 카운트
9+
int half = 12 * 3600;
10+
if(st == 0 || st == half) answer++;
11+
12+
while(st < et) {
13+
// 현재 각도 계산
14+
// 초침 -> 1초에 6도 (360도/60초)
15+
// 분침 -> 1초에 1/10도 (6도 / 60)
16+
// 시침 -> 1초에 1/120도 (6도 / 60*12)
17+
double h = (st / 120) % 360;
18+
double m = (st / 10) % 360;
19+
double s = (st * 6) % 360;
20+
21+
// 다음 각도
22+
// 0도가 된다는 것은 360도와 같음
23+
double nh = reAngle(((st+1) / 120) % 360);
24+
double nm = reAngle(((st+1) / 10) % 360);
25+
double ns = reAngle(((st+1) * 6) % 360);
26+
27+
// 초침 == 시침
28+
if(s < h && nh <= ns) answer++;
29+
// 초침 == 분침
30+
if(s < m && nm <= ns) answer++;
31+
// 시침, 분침이 모두 겹칠때
32+
if(nh == ns && nm == ns) answer--;
33+
34+
st++;
35+
}
36+
37+
return answer;
38+
}
39+
public static double changeSec(int h, int m, int s) {
40+
return (double) (h*3600 + m*60 + s);
41+
}
42+
public static double reAngle(double a){
43+
if(a == 0.0) return 360.0;
44+
return a;
45+
}
46+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /