Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. double distance_checker(double D, double v,double T, double w);
  3. int main() {
  4. FILE*fin = fopen("input.txt","r");
  5. FILE*fout = fopen("output.txt","w");
  6.  
  7. double D, T , v1 , v2, w1, w2, maximum_distance;
  8. double distance[4];
  9.  
  10. fscanf(fin,"%lf%lf%lf%lf%lf%lf", &D, &T, &v1, &v2, &w1, &w2);
  11. distance[0] = distance_checker(D, v1, T, w1);
  12. distance[1] = distance_checker(D, v2, T, w1);
  13. distance[2] = distance_checker(D, v1, T, w2);
  14. distance[3] = distance_checker(D, v2, T, w2);
  15. maximum_distance = 0;
  16. for (int i = 0; i < 4; ++i) {
  17. if (distance[i] >= maximum_distance){
  18. maximum_distance = distance[i];
  19. }
  20. if (maximum_distance > D){
  21. maximum_distance = D;
  22. }
  23. }
  24. fprintf(fout,"%lf",maximum_distance);
  25. fclose(fin);
  26. fclose(fout);
  27. return 0;
  28. }
  29.  
  30. double distance_checker(double D, double v,double T, double w) {
  31. if (v-w == 0){
  32. return 0;
  33. }
  34. double distance = (D - w * T) * v / (v - w);
  35. if (((D - w * T) / (v - w)) > T){
  36. return T*v;
  37. }
  38. if (distance>D){
  39. return D;
  40. }
  41. return distance;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement