poj 2501 Average Speed

poj 2501 Average Speed,第1张

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;}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4892943.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存