-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrafficLights
More file actions
50 lines (49 loc) · 767 Bytes
/
TrafficLights
File metadata and controls
50 lines (49 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Traffic Lights
{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
int Test = sc.nextInt();
String[]Result = new String[Test];
int i =0;
String Res = "";
while(Test-- != 0){
int x = sc.nextInt(),g = sc.nextInt(),y = sc.nextInt(),r = sc.nextInt();
while(x > 0){
x = x -g;
if(x == 0){
Res = "YELLOW";
break;
}
if(x < 0){
Res = "GREEN";
break;
}
x = x - y;
if(x == 0){
Res = "RED";
break;
}
if(x < 0){
Res = "YELLOW";
break;
}
x = x -r ;
if(x ==0){
Res = "GREEN";
}
if(x < 0){
Res = "RED";
}
}
Result[i] = Res;
i++;
}
for(int j=0 ; j < Result.length;j++){
System.out.println(Result[j]);
}
}
}