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 aef4beb

Browse files
committed
이예진: [PG] 250135 아날로그 시계_241205
1 parent 98a775b commit aef4beb

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎Programmers/Level2/YJ_250135.java‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class YJ_250135 {
2+
public int solution(int h1, int m1, int s1, int h2, int m2, int s2) {
3+
int answer = getAlarms(h2,m2,s2)-getAlarms(h1,m1,s1);
4+
return s1==0 && m1==0? answer+1 : answer;
5+
}
6+
7+
int getAlarms(int h, int m, int s){
8+
int alarms = 0;
9+
10+
int mCount = h * (60-1) + m; //1시간에 59번(60분 제외) + 1분당 1번
11+
int hCount = h * 60 + m;
12+
if(h>=12) {
13+
hCount--; //24시인 경우 -1
14+
}
15+
16+
17+
//초침과 분침이 겹칠 경우
18+
if(s*6 >= m*6 + s*0.1){ // 초침의 각도 = s * 360/60 , 분침의 각도 = m * 360/60 + s * 360/(60*60)
19+
mCount++;
20+
}
21+
//초침과 시침이 겹칠 경우
22+
if(30*(h%12) + 0.5*m + s * ((double) 1 / 120) <= s*6){ // 시침의 각도 = (h%12) * 360/12 + m * 360/(12*60) + s * 360 / (12*60*60)
23+
hCount++;
24+
}
25+
26+
alarms = mCount + hCount;
27+
return h>=12? alarms-1 : alarms;
28+
}
29+
}

0 commit comments

Comments
(0)

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