2013年9月21日 星期六

UVA 11677 - Alarm Clock

Problem link

Keyword: time

Algorithm:

Well, it's a math problem about time. Just subtract the time to get the answer. Just be careful when the time given is spanning through midnight.

Code:
#include<cstdio>

int main()
{
    int h1, m1, h2, m2;

    while( scanf( "%d %d %d %d", &h1, &m1, &h2, &m2 ) && ( h1+h2+m1+m2 ) )
    {
        if( h1 > h2 || h1 == h2 && m1 > m2 )
            h2 += 24;
        printf( "%d\n", 60 * ( h2 - h1 ) + m2 - m1 );
    }

    return 0;
}

沒有留言:

張貼留言