zoukankan      html  css  js  c++  java
  • Average Speed_时间的输入/出

    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 4994   Accepted: 2245

    Description

    You have bought a car in order to drive from Waterloo to a big city. The odometer on their car is broken, so you cannot measure distance. But the speedometer and cruise control both work, so the car can maintain a constant speed which can be adjusted from time to time in response to speed limits, traffic jams, and border queues. You have a stopwatch and note the elapsed time every time the speed changes. From time to time you wonder, "how far have I come?". To solve this problem you must write a program to run on your laptop computer in the passenger seat.

    Input

    Standard input contains several lines of input: Each speed change is indicated by a line specifying the elapsed time since the beginning of the trip (hh:mm:ss), followed by the new speed in km/h. Each query is indicated by a line containing the elapsed time. At the outset of the trip the car is stationary. Elapsed times are given in non-decreasing order and there is at most one speed change at any given time.

    Output

    For each query in standard input, you should print a line giving the time and the distance travelled, in the format below.

    Sample Input

    00:00:01 100
    00:15:01
    00:30:01
    01:00:01 50
    03:00:01
    03:00:05 140
    

    Sample Output

    00:15:01 25.00 km
    00:30:01 50.00 km
    03:00:01 200.00 km

    有趣的一题~

    【题意】:给出时间和速度,求距离

    总结:

    1、时间的输入方法:scanf("%d:%d:%d",&h,&m,&s),注意积累!

    2、关于空格的的输入控制使用char ch = getchar(),同时它还作为了本题的一个是否输出的标识控制的条件

    3、时间的输出方法:printf("%02d:%02d:%02d...

    #include<iostream>
    #include<stdio.h>
    using namespace std;
    int cal(int h,int k,int m)
    {
        return h*3600+k*60+m;
    }
    int main()
    {
        int h,k,m;
        double v=0;
        double ans=0;
        int pre=0;
        while(scanf("%d:%d:%d",&h,&k,&m)!=EOF)
        {
            char ch=getchar();
            if(ch==' ')
            {
                int a;
                scanf("%d",&a);
                int now=cal(h,k,m);
                ans+=(now-pre)*v;
                pre=now;
                v=a/3.6;
            }
            else
            {
                 printf("%02d:%02d:%02d %.2f km
    ",h,k,m,(ans+(cal(h,k,m)-pre)*v)/1000);
            }
        }
        return 0;
    }
  • 相关阅读:
    python爬虫headers设置后无效解决方案
    idea建立web项目servlet映射的地址/jsp访问不到
    bootstrap栅格系统错位问题
    python2 python3共存解决方案
    Springboot+Thymeleaf框架的button错误
    星空雅梦
    星空雅梦
    星空雅梦
    星空雅梦
    星空雅梦
  • 原文地址:https://www.cnblogs.com/iwantstrong/p/5790750.html
Copyright © 2011-2022 走看看