Jump to content

The output is right but it says wrong in Code Forces   :(

#include <iostream>#include<math.h>using namespace std;int main(){int h1,min1,h2,min2;cin>>h1>>min1>>h2>>min2;if(h1==h2)    cout<<(24*60)-fabs(min1-min2);    else if (h1>h2)        cout<<((fabs((h1-24)+fabs(h2%12))*60))-fabs(min1-min2);    else if (h2>h1)        cout<<((h2-h1)*60)-fabs(min1-min2);}

xUKgiAe.jpg

Link to comment
https://linustechtips.com/topic/267513-help-in-c/
Share on other sites

Link to post
Share on other sites

well, first of all, h1 will never be higher than h2, so you can get rid of that case, second, you don't need the math library, if h1==h2 then the answer would be m2-m1 and if h2>h1 the answer would be (h2-h1)*60+(m2-m1)

#include <iostream>using namespace std;void main(){int h1, m1, h2, m2;cin>>h1>>m1>>h2>>m2;cout<<(h2-h1)*60+(m2-m1);}

you can use this if you are too lazy to even use if clauses

this is assuming the go to bed and wake up time occur during the same day

The best way to measure the quality of a piece of code is "Oh F*** "s per line

Link to comment
https://linustechtips.com/topic/267513-help-in-c/#findComment-3633287
Share on other sites

Link to post
Share on other sites

well, first of all, h1 will never be higher than h2, so you can get rid of that case, second, you don't need the math library, if h1==h2 then the answer would be m2-m1 and if h2>h1 the answer would be (h2-h1)*60+(m2-m1)

#include <iostream>using namespace std;void main(){int h1, m1, h2, m2;cin>>h1>>m1>>h2>>m2;cout<<(h2-h1)*60+(m2-m1);}

you can use this if you are too lazy to even use if clauses

this is assuming the go to bed and wake up time occur during the same day

 

I thought about h1>h2 'cause it's 24-Hour format so h1 might be (22) and h2 (5) for example 

Link to comment
https://linustechtips.com/topic/267513-help-in-c/#findComment-3633317
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×