View Code of Problem 104

#include<stdio.h>
#include<math.h>
int main(){
	int n;
	int v1,v2,t;
	while(scanf("%d",&n)!=EOF){
		n=n*1000;
		scanf("%d %d %d",&v1,&v2,&t);	
	if(v1>0&&v2>0){
		if(v1>v2){
			double T=1.0*n/(v1-v2);
			if(T<=t){
				printf("%.2f\n",T);
			}else{
				printf("NO\n");
			}
		}else{
			printf("NO\n");
		}	
	}else if(v1<0&&v2<0){
		v1=abs(v1);
		v2=abs(v2);
		if(v2>v1){
			double T=1.0*n/(v2-v1);
			if(T<=t){
				printf("%.2f\n",T);
			}else{
				printf("NO\n");
			}
		}else{
			printf("NO\n");
		}
	}else if(v1>0&&v2<0){
		v2=abs(v2);
		double T=1.0*n/(v2+v1);
		printf("%.2f\n",T);
	}else if(v1<0&&v2>0){
		printf("NO\n");
	}
	} 
	return 0;
}

Double click to view unformatted code.


Back to problem 104