hdu1036

注意精度进OKl了。。。。。

http://acm.hdu.edu.cn/showproblem.php?pid=1036

15103652_zWvD.gif 15103652_smU2.gif View Code

    
#include " iostream "
using namespace std;
int main()
{
int n;
double s;
int m;
char ch[ 100 ];
int i,j,k;
cin
>> n >> s;
while (cin >> m)
{
int mark = 0 ;
int sum = 0 ;
for (i = 0 ;i < n;i ++ )
{
cin
>> ch;
if (ch[ 0 ] == ' - ' ){ mark = 1 ; continue ;}
sum
+= (ch[ 0 ] - ' 0 ' ) * 3600 ;
sum
+= ((ch[ 2 ] - ' 0 ' ) * 10 + (ch[ 3 ] - ' 0 ' )) * 60 ;
sum
+= (ch[ 5 ] - ' 0 ' ) * 10 + ch[ 6 ] - ' 0 ' ;
}
if (mark == 1 ) printf( " %3d: -\n " ,m);
else
{
int y = sum / s;
if (sum / s - y > 0.5 ) y=y+1 ; // 精度处理,四舍五入
printf( " %3d: %d: " ,m,y / 60 );
if (y % 60 < 10 ) printf( " 0 " );
printf(
" %d min/km\n " ,y % 60 );
}
}
return 0 ;
}

转载于:https://my.oschina.net/garyun/blog/602809

猜你喜欢

转载自blog.csdn.net/weixin_33877092/article/details/91774219
今日推荐