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. [示例] 使用 TStopwatch 计时

    使用 TStopwatch 计时 uses System.Diagnostics; var t1: TStopwatch; begin t1 := TStopwatch.StartNew; // do ...

  2. Linux Guard Service - 守护进程的作用、用途、父进程标识的特点

    让test2直接成为守护进程 [root@localhost 02]# cat test2.c //test2 #include<stdio.h> #include<unistd.h ...

  3. elasticsearch(0.90.10)安装配置+超多插件!!

    一)安装elasticsearch 1)下载elasticsearch-0.90.10,解压,运行\bin\elasticsearch.bat (windwos) 2)进入http://localho ...

  4. c#设计模式系类:亨元模式

    一.引言 在软件开发过程中,如果我们需要重复使用某个对象的时候,如果我们重复地使用new创建这个对象的话,这样我们在内存就需要多次去申请内存空间了,这样可能出现内存使用越来越多的情况,这样的问题是非常 ...

  5. python 特性:height-->while

    """ 出题:height 女生找对象 男生在1米-1.5米之间 小强你在哪里? 男生在1.5-1.7米之间 没有安全感 男生在1.7 - 1.8米之间 帅哥 留个电话 ...

  6. “全栈2019”Java第六十八章:外部类访问内部类成员详解

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  7. “全栈2019”Java第二十四章:流程控制语句中决策语句switch下篇

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  8. To 高一

    Linux 坑待填 Special Judge 什么是 Special Judge?有的题目会让你输出任意一个解即可AC,或者是让你输出部分答案能取得本测试点部分得分,或者是按照方案的优秀程度给你分, ...

  9. Linux sort和uniq命令的应用

    sort: 选项: -b 忽略每行前面开始出的空格字符 -c 检查文件是否已经按照顺序排序 -d 排序时,处理英文字母.数字及空格字符外,忽略其他的字符 -f 排序时,将小写字母视为大写字母 -i 排 ...

  10. 2016级算法第四次上机-A.Bamboo 和人工zz

    Bamboo和人工ZZ 题意: 非常直白,经典的动态规划矩阵链乘问题 分析: 矩阵链A1A2..An满足结合律,可以使用加括号的方式,降低运算代价. 一个pq的矩阵和一个qr的矩阵相乘,计算代价为pq ...