-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLift.java
More file actions
76 lines (62 loc) · 1.86 KB
/
Lift.java
File metadata and controls
76 lines (62 loc) · 1.86 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//There are n floors in BH3 and only 2 lifts. Initially Lift A is at the ground floor and Lift B at the top floor. Whenever someone calls the lift from N th floor, the lift closest to that floor comes to pick him up. If both the lifts are at equidistant from the N th floor, them the lift from the lower floor comes up.
//INPUT
//First line contains a integer T denoting the number of test cases.
//Next T lines contains a single integer N denoting the floor from which lift is called.
//OUTPUT
//Output T lines containing one character "A" if the first lift goes to N th floor or "B" for the second lift.
//CONTRAINTS
//0 <= N <= n
//1 <= T <= 100000
//Explanation
//3rd floor calls, Lift A(0) goes there.
//5th floor calls, Lift A(3) and Lift B(7) are equidistant from 5, so Lift from l//owest floor goes there i.e. A.
import java.util.Scanner
public class lift{
public static void main(String args[])
{
Scanner in= new Scanner(System.in);
System.out.println("Etner the max no of floors:- ");
int tf=in.nextInt();
int A=0,B=tf;
System.out.println("Enter the number of test cases that you want to run");
int test = in.nextInt();
for (int i = 0; i < test; i++) {
lift_function(lift_A, lift_B, top_floor);
}
}
public static void lift_function(int A, int B, int tf)
{
Scanner inp=new Scanner(System.in);
System.out.println("Which floor :- ");
int call=inp.nextInt();
if(call<=tf) {
if(call>A && call<B) {
if(call-A < B-call) {
System.out.println("Lift");
A=call;
}
else if(call-A > b-call) {
system.out.ptintln("Lift");
A=call;
}
}
else if(call>A && call>B) {
if(a-call< call-b){
system.out.println("Lift");
A=call;
}
else if (A-call > call-B) {
System.out.println("Lift");
B=call;
}
else {
System.out.println("Lift");
A=call;
}
}
}
else {
System.out.println("Invalid floor");
}
}
}