UVA 579 - ClockHands(水)

题目链接

只要把钟表想清楚就没问题了,分针一分钟转6度,而时针一分钟转0.5度,1小时转30度,减减算算就OK了。

 1 #include <stdio.h>

 2 #include <string.h>

 3 int main()

 4 {

 5     char end[10] = "0:00";

 6     char p[10];

 7     int i,hour,min,len;

 8     double sum;

 9     while(scanf("%s",p)!=EOF)

10     {

11         if(strcmp(p,end)==0)

12         break;

13         len = strlen(p);

14         for(i = 0;;i ++)

15         {

16             if(p[i] == ':')

17             {

18                 if(i == 2)

19                 hour = 10 + p[i-1]-'0';

20                 else

21                 hour = p[i-1] - '0';

22                 min = (p[i+1]-'0')*10 + p[i+2]-'0';

23                 break;

24             }

25         }

26         sum = (hour*30+min*0.5)-min*6;

27         if(sum < 0)

28         sum = -sum;

29         if(sum >= 180)

30         sum = 360-sum;

31         printf("%.3lf\n",sum);

32     }

33     return 0;

34 }

你可能感兴趣的:(Lock)