首页 > 其他 > 详细

【HDOJ】2395 Alarm Clock

时间:2014-12-28 00:18:27      阅读:345      评论:0      收藏:0      [点我收藏+]

水题。

 1 /* 2395 */
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 
 6 #define MAXL 20
 7 
 8 char src[MAXL], des[MAXL];
 9 
10 int min(int a, int b) {
11     return a<b ? a:b;
12 }
13 
14 int abs(int x) {
15     return x<0 ? -x:x;
16 }
17 
18 int main() {
19     int t;
20     int sh, sm1, sm0;
21     int dh, dm1, dm0;
22     int i, j, k, tmp;
23     int ans;
24     
25     #ifndef ONLINE_JUDGE
26         freopen("data.in", "r", stdin);
27     #endif
28     
29     scanf("%d", &t);
30     while (t--) {
31         scanf("%s %s", src, des);
32         ans = 0;
33         
34         // handle source
35         k = strchr(src, :) - src;
36         sh = 0;
37         for (i=0; i<k; ++i)
38             sh = 10*sh + src[i]-0;
39         sm1 = src[k+1] - 0;
40         sm0 = src[k+2] - 0;
41         
42         // handle des
43         j = strchr(des, :) - des;
44         dh = 0;
45         for (i=0; i<j; ++i)
46             dh = 10*dh + des[i]-0;
47         dm1 = des[j+1] - 0;
48         dm0 = des[j+2] - 0;
49         
50         // calculate ans
51         if (des[j+3] != src[k+3])
52             ++ans;
53         ans += min(abs(sm0-dm0), 10-abs(sm0-dm0));
54         ans += min(abs(sm1-dm1), 6-abs(sm1-dm1));
55         ans += min(abs(sh-dh), 12-abs(sh-dh));
56         
57         if (ans == 1)
58             printf("Going from %s to %s requires %d push.\n", src, des, ans);
59         else
60             printf("Going from %s to %s requires %d pushes.\n", src, des, ans);
61     }
62     
63     return 0;
64 }

 

【HDOJ】2395 Alarm Clock

原文:http://www.cnblogs.com/bombe1013/p/4189397.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!