Lift quiries

Problem:-

There are 7 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 denoting the number of test cases.
Next lines contains a single integer 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 <= 7
1 <= T <= 100000


SAMPLE INPUT
2
3
5
SAMPLE OUTPUT
A
A
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 lowest floor goes there i.e. A.
Time Limit:1.0 sec(s) for each input file.
Memory Limit:256 MB
Source Limit:1024 KB

solution:-

#include<stdio.h>
void main()
{
     long int n,t,i,g=0,u=7;
     scanf(“%ld”,&t);
     for(i=0;i<=t1;i++)
     {
         scanf(“%ld”,&n);
         if((ng)<=(un))
         {
         printf(“An”);
         g=n;
         }
         else
         {
         printf(“Bn”);
         u=n;
         }
     }
}

Leave a Reply

Your email address will not be published.