|
| 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