hdu 1209 clocks wrong answer 我的错误代码(没审好题唉,角度一样后,还要按小时排序。

#include<stdio.h>
#include
<string.h>
#include
<stdlib.h>
#include
<math.h>
int cmp(const void *a,const void *b)
{
return *(double* )a > *(double *)b ?1 :-1;
}
double fun(int x,int y)
{
if(x>12)

x
=x-12;

return abs(x*30-(y/5.0)*30)> 180 ? 360-abs(x*30-(y/5.0)*30):abs(x*30-(y/5.0)*30);
}
struct node
{
double a;
int b;
}c[
10];

int main( )
{
int N;
scanf(
"%d",&N);
while(N--)
{
int i,j,h[10],m[10];
memset(h,
0,sizeof(h));
memset(m,
0,sizeof(m));

for(i=0;i<5;i++)
{
c[i].a
=0;
c[i].b
=0;
}
for(i=0;i<5;i++)
scanf(
"%d:%d",&h[i],&m[i]);

for(i=0;i<5;i++)
{
c[i].a
=fun(h[i],m[i]);

c[i].b
=i;

}
qsort(c,
5,sizeof(c[0]),cmp);

printf(h[c[
2].b]<10?"0%d:":"%d:",h[c[2].b]);
printf(m[c[
2].b]<10?"0%d\n":"%d\n",m[c[2].b]);

}
//system("pause");
return 0;
}
正确代码:
正确代码:
正确代码:


posted on 2011-04-10 21:18  more think, more gains  阅读(223)  评论(0编辑  收藏  举报

导航