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. Centos7 因内存 可用大小不足,被killed的解决办法

    Linux的内存分配采取的是一种更加积极的分配策略,它假设应用申请了内存空间后并不会立即去使用它,所以允许一定量的超售,当应用真的需要使用它的时候,操作系统可能已经通过回收了其他应用的内存空间而变得有 ...

  2. C#操作系统计划任务

    首先需要引用system32下的taskschd.dll 测试环境:win8+vs2012+.net4.0 /// <summary> /// 删除任务 /// </summary& ...

  3. Markdown应用样例

    Markdown编辑器: https://www.typora.io/ Markdown主题: http://theme.typora.io/ 1.标题 一号标题 三号标题 六号标题 2.超链接 Cm ...

  4. consul ACL2

    简介 Consul有多个组件,但是整体上,consul通常作为服务发现工具来使用. Consul主要由以下特点: 服务发现 健康检查 KV存储 多数据中心 Consul一般与zookeeper,ser ...

  5. 【Apache系列】linux下Apache的常用操作

    1. 启动/停止 1.1假设你的apahce安装目录为/usr/local/apache2,这些方法适合任何情况 apahce启动命令: /usr/local/apache2/bin/apachect ...

  6. Ubuntu16.04以root身份登入!

    首先以非root用户身份登入系统. 1,修改root密码:启动shell,随后在shell里面输入命令: sudo passwd root 最后输入root要使用的密码,需要输入两次,这样root密码 ...

  7. 接口测试:添加cookie以及身份验证

    添加cookie以及身份验证的接口文档: cookie:存放在本地的一个键值对 session:存放在服务端的一个键值对 学生金币充值接口文档: 一.使用postman进行测试 由于进行学生金币充值操 ...

  8. 十,PHP下载文件

    1,文件类型 (1)文本文件,如xx.txt. (2)二进制文件,如图片.视频.音频. 2,文件下载流程如下图所示,首先浏览器向服务器发送下载请求,服务器将下载资源读入内存,再通过http将资源返回到 ...

  9. python的数据结构分类,以及数字的处理函数,类型判断

    python的数据结构分类: 数值型 int:python3中都是长整形,没有大小限制,受限内存区域的大小 float:只有双精度型 complex:实数和虚数部分都是浮点型,1+1.2J bool: ...

  10. 4,临界区 之 synchronized

    前提背景:多个并发线程共享同一个资源时,为防止这些共享资源可能出现的错误或数据不一致问题,提出了临界区的概念 临界区: 指一个用以访问共享资源的代码块,这个代码块在同一时间内只能允许一个线程访问 实现 ...