題目鏈接:uva 1529 - Clock
題目大意:給出兩個時間,問從第一個時間變成第二個時間分針會和時針重疊幾次。
解題思路:兩個針重疊的時間是固定的,只要處理出這些重疊的時刻,在判斷說給得時間區間包含的個數即可。
#include#include #include const int T = 12 * 60 * 100; const int D = 6545; int sh, sm, eh, em; int solve (int s, int t) { if (t < s) t += T; return t / D - (s - 100) / D; } int main () { printf("Program 3 by team X\n"); printf("Initial time Final time Passes\n"); while (scanf("%d%d%d%d", &sh, &sm, &eh, &em) == 4) { int s = (sh * 60 + sm) * 100; int t = (eh * 60 + em) * 100; printf(" %02d:%02d %02d:%02d", sh, sm, eh, em); printf("%8d\n", solve(s, t)); } printf("End of program 3 by team X\n"); return 0; }