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. iOS AppStore个人开发者账号申请

    一.申请Apple Developer账号 1.注册App ID 1.打开苹果开发者网页,选择Account,注册Apple ID.   2.填写注册信息 3.地区选择China,填写好验证码,点击C ...

  2. 神器与经典--sp_helpIndex

    ======================================================= 每每和那些NB的人学习技术的时候,往往都佩服他们对各个知识点都熟捻于心,更佩服的是可以在 ...

  3. MFC学习(一)

    参考: VS项目属性的一些配置项的总结(important) 1. 项目配置 项目属性定制 常规(General) -> 平台工具集(Platform Toolset):vs2012中默认为&q ...

  4. SQL SERVER先判断视图是否存在然后再创建视图的语句

    如果我们的语句为: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 IF NOT EXISTS(SELECT 1 FROM sys.views WHERE name='Report_I ...

  5. nowcoder(牛客网)提高组模拟赛第一场 解题报告

    T1 中位数(二分) 这个题是一个二分(听说是上周atcoder beginner contest的D题???) 我们可以开一个数组b存a,sort然后二分b进行check(从后往前直接遍历check ...

  6. Mysql 学习笔记09

    ---Mysql 的主从复制  replication 1 主从复制原理 至少有2台服务器,一台主服务器,一台从服务器,主服务器的所有改动,如 insert update delete 操作,都会同步 ...

  7. Mac 上安装python3

    1.安装包管理器 去包管理器官网按照提示安装包管理器 Homebrew 2.安装python3 安装完Homebrew ,输入指令安装python3 brew install python3 3.安装 ...

  8. BAT机器学习面试1000题系列(41-45题)

    41.线性分类器与非线性分类器的区别以及优劣 如果模型是参数的线性函数,并且存在线性分类面,那么就是线性分类器,否则不是.常见的线性分类器有:LR,贝叶斯分类,单层感知机.线性回归常见的非线性分类器: ...

  9. acedSSGet使用自定义提示字符:$模式

          ads_name ss; struct resbuf *pRbList=NULL; pRbList=acutBuildList(RTDXF0,_T("lwpolyline,ins ...

  10. [ActionSprit 3.0] FMS安装与测试

    1.运行Flash Media Server4.5.exe,安装选项可全默认,序列号可不填:输入用户名和密码需记住,登录时要用. 2.安装完成,在安装目录C:\Program Files\Adobe\ ...