Average Speed
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4842   Accepted: 2168

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

Source

 
分析:
模拟,注意一开始可能就问,或者一开始赋予0的速度。
getchar()判断是询问还是更新。
具体代码:
 #include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<stack>
using namespace std;
double trans(string s){
return ((s[]-'')*+s[]-'')*+((s[]-'')*+s[]-'')*+(s[]-'')*+s[]-'';
}
int main(){
string s;
double nowspeed=,nowtime=,speed,time,havdrive=;
while(cin>>s){
time=trans(s);
if(getchar()==' '){//速度更新,已行驶的路程更新,基准时间更新
cin>>speed;
havdrive+=(time-nowtime)/*nowspeed;
nowtime=time;
nowspeed=speed;
}
else{
cout<<s;
printf(" %.2f km\n",havdrive+(time-nowtime)/*nowspeed);//写成printf(" %.2f km\n",havdrive+(time-nowtime)/3600*nowspeed)就错了!!
}
}
return ;
}

poj 2501 Average Speed的更多相关文章

  1. POJ 2501

    #include<iostream> #include<iomanip> #include<stdio.h> #include<string> #inc ...

  2. English: Class Speed

    Xx_Introduce https://www.jianshu.com/p/d1c1b84d89e8 Please protection,respect,love,"China's Int ...

  3. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  4. etcd api 接口

    etcd api接口 基本操作api: https://github.com/coreos/etcd/blob/6acb3d67fbe131b3b2d5d010e00ec80182be4628/Doc ...

  5. Ubuntu 查询 so 归属的 package

    . . . . . 今天 LZ 在运行一个程序的时候,出现找不到 so 库的情况: >$ ./core ./core: error : cannot open shared object fil ...

  6. curl详解

    用途说明 curl命令是一个功能强大的网络工具,它能够通过http.ftp等方式下载文件,也能够上传文件.其实curl远不止前面所说的那些功能,大家可以通过man curl阅读手册页获取更多的信息.类 ...

  7. 升级ruby后再安装cocodPod

    1.移除现有的Ruby $gem sources --remove https://rubygems.org/ 2.使用淘宝镜像 $gem sources -a https://ruby.taobao ...

  8. SWFUpload简介及中文参考手册(share)

    SWFUpload SWFUpload 版本 2 概览 (Overview) 入门( Getting Started) js对象 (SWFUpload JavaScript Object) 构造器(C ...

  9. iOS 学习笔记二【cocopods安装使用和安装过程中遇到的问题及解决办法】【20160725更新】

    在osx 10.11之前cocopods问题不多,但是升级到11之后的版本,之前的cocopods大多用不了,需要重新安装,对于我这种使用测试版系统的技术狂来说,每次都需要重新安装很多东西, 当然,c ...

随机推荐

  1. HTTP 常见异常状态及Delphi IDHTTP 控件处理方式

    以下部分为网上查找,部分为工作中整理 200:请求成功 202:请求被接受,但处理尚未完成 302:请求到的资源在一个不同的URL处临时保存     处理方式:重定向到临时的URL(IDHTTP处理方 ...

  2. [LeetCode 题解]: Add Two Numbers

    You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...

  3. 一个自定义MVP .net框架 AngelFrame

    摘要:本篇是本人在完成.net平台下一个项目时,对于MVP框架引发的一些思考,以及开发了一个小型的配置型框架,名字叫作AngelFrame.这个项目属于前端桌面管理系统的一部分,最终要集成进去. 关键 ...

  4. Replication--使用MSlogreader_history查看日志读起的延迟和事务命令

    --======================================================================== MSlogreader_history 表存放本地 ...

  5. atan2()如何转换为角度

    atan2()如何转换为角度 Math.atan2()函数返回点(x,y)和原点(0,0)之间直线的倾斜角.那么如何计算任意两点间直线的倾斜角呢?只需要将两点x,y坐标分别相减得到一个新的点(x2-x ...

  6. 深入了解java虚拟机(JVM) 第三章 内存区域----堆空间

    一.堆的含义 jvm堆的区域主要是用来存放对象的实例,它的空间大小是JVM内存区域中占比重最大的,也是jvm最大的内存管理模块,最重要的是,这个区域是垃圾收集器主要管理的区域,这意味着我们在考虑垃圾回 ...

  7. Lvs IP负载均衡技术

    Lvs集群的通用结构 Lvs集群采用IP负载均衡技术,属于IP层的交换(L4),具有很好的吞吐率.调度器分析客户端到服务器的IP报头信息,将请求均衡地转移到不同的服务器上执行,且调度器自动屏蔽掉服务器 ...

  8. lexical or preprocessor issue file not found in Xcode

    The very last suggestion is all I needed to fix this issue. Close & re-open Xcode.

  9. 机器学习中的范数规则化之 L0、L1与L2范数、核范数与规则项参数选择

    装载自:https://blog.csdn.net/u012467880/article/details/52852242 今天我们聊聊机器学习中出现的非常频繁的问题:过拟合与规则化.我们先简单的来理 ...

  10. docker-compose部署mysql配置

    docker-compose部署mysql配置文件如下 version: ' services: mysql: image: mysql environment: - MYSQL_ROOT_PASSW ...