zoukankan      html  css  js  c++  java
  • 杭电oj1036c++详解

    1.格式,必须严格按照格式输出
    2.当判断出输入的时间段中含有“-”不能停止输入,要将所有的数据都输入进来
    3.样例中不包含小时,但是应该将小时也考虑进时间
    4.对于最后求得秒要进行四舍五入,可以直接调用函数round.
    具体的代码如下:
    
    #include<iostream>
    #include<string>
    #include<iomanip>
    #include<sstream>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    int main(){
        int num;
        double dis;
        string time;
        int name;
        int h1,m1,s1;
        bool flag=false;
        cin>>num>>dis;
        string temp;
        while(cin>>name){
            int sumtime=0;
            flag=false;
            for(int i=0;i<num;i++){
                cin>>temp;
                if(temp=="-:--:--"){
                flag=true;
            }
                h1=temp[0]-'0';
                m1=(temp[2]-'0')*10+(temp[3]-'0');
                s1=(temp[5]-'0')*10+(temp[6]-'0');
                sumtime=sumtime+h1*3600+m1*60+s1;
            }
            if(flag){
                cout<<setiosflags(ios::right)<<setw(3)<<name<<":"<<" -"<<endl;
            }else{
                int secPerKilo = round(sumtime/dis);
                int minus = secPerKilo/60;
                int secs = (int)(secPerKilo)%60;
            cout<<setiosflags(ios::right)<<setw(3)<<name<<": "<<minus<<":";
            if(secs<10){
               cout<<0;    
            }
            cout<<secs<<" min/km"<<endl;
            }
                
        } 
    }
  • 相关阅读:
    go学习中的零散笔记
    git reset --hard与git reset --soft的区别
    php必学必会
    gdb 解core
    php学习
    高仿京东到家APP引导页炫酷动画效果
    RxHttp
    SVN回滚文件
    遍历枚举
    python3 多线程
  • 原文地址:https://www.cnblogs.com/ljysy/p/12663637.html
Copyright © 2011-2022 走看看