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;
            }
                
        } 
    }
  • 相关阅读:
    计算机网络知识 第一部分
    LAMP环境安装
    Axure RP 交互设计
    Axure RP 界面功能
    Axure RP 界面功能介绍
    Axure RP 第一部分
    Grub管理修改root口令
    MYSQL 部分练习题
    工作日志示例
    计算机网络的分类
  • 原文地址:https://www.cnblogs.com/ljysy/p/12663637.html
Copyright © 2011-2022 走看看