栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2501 Average Speed

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2501 Average Speed

#include <cstdlib>   #include <cctype>   #include <cstring>   #include <cstdio>   #include <cmath>   #include <algorithm>   #include <vector>   #include <string>   #include <iostream>   #include <sstream>   #include <map>   #include <set>   #include <queue>   #include <stack>   #include <fstream>   #include <numeric>   #include <iomanip>   #include <bitset>   #include <list>   #include <stdexcept>   #include <functional>   #include <utility>   #include <ctime>using namespace std;ifstream fin("aa.txt");#define MAX(a,b) ((a) > (b) ? (a) : (b))#define MIN(a,b) ((a) < (b) ? (a) : (b))#define MEM(a,b) memset((a),(b),sizeof(a))#define BLANK(a) for(int i = 0; i < (a); i ++) printf(" ")vector<string> vs;vector<double> v;int getnum(string str){int h = (str[0]-'0')*10+str[1]-'0';int m = (str[3]-'0')*10+str[4]-'0';int s = (str[6]-'0')*10+str[7]-'0';return h*3600+m*60+s;}double sub(string str1, string str2){return (getnum(str1)-getnum(str2))/3600.0;}int str2num(string str, int cur){int ans = 0;for(int i = cur; i < str.length(); i++){ans = ans*10+str[i]-'0';}return ans;}int main(){string str;vs.push_back("00:00:00 0");v.push_back(0);while(getline(cin,str)){vs.push_back(str);v.push_back(0);}int pre = -1;int sp = -1;for(int i = 0; i < vs.size(); i++){int cur = vs[i].find(' ');if(cur != -1){if(i != 0)v[i] = v[pre] + sub(vs[i],vs[pre])*sp;sp = str2num(vs[i],cur+1);pre = i;}else{v[i] = v[pre] + sub(vs[i],vs[pre])*sp;printf("%s %.2f kmn",vs[i].c_str(),v[i]);}}    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/366987.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号