Header Ad

HackerEarth Simon cannot sleep problem solution

In this HackerEarth Simon cannot sleep problem solution It's 12 o'clock at midnight (00 : 00) and Simon cannot sleep! So he decided to stare at the clock on his wall until he falls asleep.

He saw the clock's hands and got to thinking 'How many times they'll pass each other until I fall asleep' hh : mm. Imagine that he fell asleep at . Now, you must figure out how many times clock's hands overlap from 00 : 00 to hh : mm (including 00 : 00 and hh : mm).

hackerEarth Simon cannot sleep problem solution

hackerEarth Simon cannot sleep problem solution.


#include <bits/stdc++.h>

using namespace std;

int h, m;
char c;

int moji(int h, int m){
int p = m / 5;
int ans = h;
if(h >= 12)
h -= 12, ans--;
if(p > h) ans++;
else if (p == h){
if(m % 5 >= m / 12.0)
ans++;
}
return ans;
}

int ali(int h, int m){
int ans = h;
if(h >= 12)
h -= 12, ans--;
return ans + (11 * m >= h * 60);
}

int main(){
cin >> h >> c >> m;
cout << moji(h, m) << endl;

return 0;
}

second solution

h, m = map(int, input().split(':'))

print((m * 12 >= h % 12 * 60 + m) + (h if h < 12 else h - 1))


Post a Comment

1 Comments

  1. in the solution we are not calling ali function how it is executed

    ReplyDelete