Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include<cmath>
  2. #include<fstream>
  3. #include<iostream>
  4. using namespace std;
  5.  
  6. int main(){
  7. double x = 0, y = 0, prex = 0, prey = 0;
  8. int num_trip;
  9. double cum_dis = 0, cum_cost = 0;
  10. //***************************************************************
  11. //opening file
  12. ifstream fin("taxi.txt");
  13. if(!fin){
  14. cout << "Failed to open file!" << endl;
  15. return 0;
  16. }
  17. //***************************************************************
  18. double distance = 0, cost = 0;
  19. bool round_logic = 0;
  20. int num_stop = 0;
  21. cout <<
  22. while(fin >> round_logic){
  23. num_trip++;
  24. fin >> num_stop;
  25. for(int i = 0;i < num_stop;i++){
  26. prex =x;
  27. prey = y;
  28. fin >> x >> y;
  29. distance = distance + sqrt((x - prex) * (x - prex) + (prey - y) * (prey - y));
  30. }
  31.  
  32. cost = distance * 2.7 + num_stop * 11;
  33. if(round_logic){
  34. cost = cost + 2.7 * sqrt(x*x + y*y);
  35. distance = distance + sqrt(x*x + y*y);
  36. }
  37. cum_cost += cost;
  38. cum_dis += distance;
  39.  
  40. cout << num_trip << " " << round_logic << " " << num_stop << " " << distance << " " << cost << " " << cum_dis << " " << cum_cost << endl;
  41. cost = 0;
  42. distance = 0;
  43. x = 0;
  44. y = 0;
  45. }
  46.  
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement