zoukankan      html  css  js  c++  java
  • hdu-1036(格式题+精确度)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1036

    心得:注意,要进行四舍五入的精确可以用+0.5实现。

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    using namespace std;
    char str[20];
    int main(void)
    {
        double tim,dis;
        int pt,n,i,h,mm,ss,t1,t2;
        scanf("%d %lf",&n,&dis);
        while(~scanf("%d",&pt))
        {
            int fg=0;
            tim=0;
            for(i=0;i<n;i++)
            {
                scanf("%s",str);
                if(str[0]=='-') fg=1;
                else
                {
                    h=str[0]-'0';
                    mm=(str[2]-'0')*10+(str[3]-'0');
                    ss=(str[5]-'0')*10+(str[6]-'0');
                    tim+=h*3600+mm*60+ss;
                }
            }
            printf("%3d:",pt);
            if(fg==1)
            {
                printf(" -
    ");
            }
            else
            {
                int sum=(int)(tim/dis+0.5);
                t1=sum/60,t2=sum%60;
                printf(" %d:%02d min/km
    ",t1,t2);
            }
        }
        return 0;
    }
  • 相关阅读:
    封装
    魔术方法类与有关面向对象的关键字
    JS基础
    轮播效果
    进度条效果
    2018年6月
    2018年5月
    Monte Carlo tree search 学习
    2018年4月
    pachi 学习
  • 原文地址:https://www.cnblogs.com/2018zxy/p/9745661.html
Copyright © 2011-2022 走看看