View Code of Problem 12

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n,df,t,i=1;
		double f0,f1,dis,jt;
		double v,c=299792458;
		int dd=3,r=200000;
		n=sc.nextInt();
		while(n>0) {
			df=sc.nextInt();
			f0=sc.nextDouble();
			f1=sc.nextDouble();
			t=sc.nextInt();
			dis=c*(t*1e-6)/2;
			v=c*(f1-f0)/(f1+f0);
			if(df==1) {
				System.out.println("Target"+i+":NO:ONE OF US");
			}
			else {
				if(v<=0) {
					System.out.println("Target"+i+":NO:AWAY");
				}
				else {
					if(dis<r) {
						if(dd>0) {
							System.out.println("Target"+i+":YES");
							dd--;
						}
						else {
							System.out.println("Target"+i+":NO:NEXT TIME");
						}
					}
					else {
						jt=(dis-r)/v;
						System.out.println("Target"+i+":NO:"+String.format("%.4f", jt));
					}
				}
			}
			
			i++;
			n--;
			
		}
	}
	

}

Double click to view unformatted code.


Back to problem 12