View Code of Problem 104

#include <iostream>
#include <math.h>
using namespace std;

int main(){
    double n,v1,v2,t,time,s;
    while(scanf("%lf%lf%lf%lf",&n,&v1,&v2,&t)!=EOF){
        if(n==0)
            printf("0.00\n");
        if((v1<=0&&v2>=0)||(v1>0&&v2>0&&v2>=v1)||(v1<0&&v2<0&&v2>=v1))
            printf("NO\n");
        else if(v1>=0&&v2<=0){
            time = n*1000/(v1-v2);
            if(time<=t)
                printf("%.2lf\n",time);
            else
                printf("NO\n");
        }
        else{
            s = (v1>v2)?v1-v2:v2-v1;
            time = n/s;
            if(time<=t)
                printf("%.2lf\n",time);
            else
                printf("NO\n");
        }
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 104