Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cmath>
- #include<fstream>
- #include<iostream>
- using namespace std;
- int main(){
- double x = 0, y = 0, prex = 0, prey = 0;
- int num_trip;
- double cum_dis = 0, cum_cost = 0;
- //***************************************************************
- //opening file
- ifstream fin("taxi.txt");
- if(!fin){
- cout << "Failed to open file!" << endl;
- return 0;
- }
- //***************************************************************
- double distance = 0, cost = 0;
- bool round_logic = 0;
- int num_stop = 0;
- cout <<
- while(fin >> round_logic){
- num_trip++;
- fin >> num_stop;
- for(int i = 0;i < num_stop;i++){
- prex =x;
- prey = y;
- fin >> x >> y;
- distance = distance + sqrt((x - prex) * (x - prex) + (prey - y) * (prey - y));
- }
- cost = distance * 2.7 + num_stop * 11;
- if(round_logic){
- cost = cost + 2.7 * sqrt(x*x + y*y);
- distance = distance + sqrt(x*x + y*y);
- }
- cum_cost += cost;
- cum_dis += distance;
- cout << num_trip << " " << round_logic << " " << num_stop << " " << distance << " " << cost << " " << cum_dis << " " << cum_cost << endl;
- cost = 0;
- distance = 0;
- x = 0;
- y = 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement