Seating Arrangement Problem - HackerEarth


SOLUTION FOR SEATING ARRANGEMENT PROBLEM - HACKEREARTH

PROBLEM

Akash and Vishal are quite fond of travelling. They mostly travel by railways. They were travelling in a train one day and they got interested in the seating arrangement of their compartment. The compartment looked something like 





So they got interested to know the seat number facing them and the seat type facing them. The seats are denoted as follows : 
  • Window Seat : WS
  • Middle Seat : MS
  • Aisle Seat : AS
You will be given a seat number, find out the seat number facing you and the seat type, i.e. WSMS or AS.

INPUT
First line of input will consist of a single integer T denoting number of test-cases. Each test-case consists of a single integer N denoting the seat-number.

OUTPUT
For each test case, print the facing seat-number and the seat-type, separated by a single space in a new line.

CONSTRAINTS
  • 1<=T<=105
  • 1<=N<=108
SAMPLE INPUT

2
18
40
SAMPLE OUTPUT
19 WS
45 AS












PROGRAM

#include <stdio.h>

int main()
{
    int T,i,N[100000];
    scanf("%d",&T);
    for(i=0;i<T;i++)
    {
        scanf("\n%d",&N[i]);
    }
    for(i=0;i<T;i++)
    {
        if(N[i]%6==0||N[i]%6==1)
        {
            if(N[i]%12==0)
                printf("%d WS",N[i]-11);
            else if(N[i]%12==1)
                printf("%d WS",N[i]+11);
            else if(N[i]%6==0)
                printf("%d WS",N[i]+1);
            else
                printf("%d WS",N[i]-1);
            printf("\n");
        }
        else if((N[i]-2)%3==0)
        {
            if(N[i]%12==2)
                printf("%d MS",N[i]+9);
            else if((N[i]-3)%12==2)
                printf("%d MS",N[i]+3);
            else if((N[i]-6)%12==2)
                printf("%d MS",N[i]-3);
            else
                printf("%d MS",N[i]-9);
            printf("\n");
        }
        else
        {
            if((N[i]-3)%12==0)
                printf("%d AS",N[i]+7);
            else if(N[i]%12==4)
                printf("%d AS",N[i]+5);
            else if(N[i]%12==9)
                printf("%d AS",N[i]-5);
            else
                printf("%d AS",N[i]-7);
            printf("\n");
        }
    }
}


I have hope!! This will helpful to you !!! 
Thank You!!!
Stay tune for next blog!!!!


Comments

  1. Replies
    1. # Python
      def checkSeat(T):
      while(T>0):
      N = int(input())
      N = N + 2 *(6-(N-1)%12)-1
      if(N % 6 < 2 ):
      val = N
      print(str(val)+" "+"WS")
      elif(N % 6 == 2 or N % 6 == 5):
      val = N
      print(str(val)+" "+"MS")
      else:
      val = N
      print(str(val)+" "+"AS")
      T-=1

      if __name__ == "__main__":
      T = int(input())
      checkSeat(T)

      Delete
    2. after running it taking many inputs can you tell me how to get perfect output

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Can I get an algorithm for this code ??

    ReplyDelete
  4. instead of while using for loop we have to get:
    n=int(input())
    if(1<=n<=(10**5)):
    l=[]
    for i in range(1,n+1):
    k=int(input())
    l.append(k)
    for i in l:
    j=i+2*(6-(i-1)%12)-1
    if (j%6 < 2):
    print(str(j)+" "+"WS")
    elif((j%6 == 2) or (j%6==5)):
    print(str(j)+" "+"MS")
    else:
    print(str(j)+" "+"AS")
    else:
    pass

    ReplyDelete
  5. nice formula brother thats great..

    ReplyDelete
  6. def seatingArrangement(seatNumber):
    seatModulus = seatNumber % 12
    # print("seatModulus",seatModulus)
    # print(seatNumber/12)
    ceilValue = math.ceil(seatNumber / 12)
    # print("ceil",ceilValue)
    nearestMultipleOfTwelve = ceilValue * 12
    # print("neares",nearestMultipleOfTwelve)
    oppositeSeat = nearestMultipleOfTwelve - (seatModulus - 1)
    # print("opp",oppositeSeat)
    print(oppositeSeat,end=" ")
    if ( seatModulus in [1 , 6, 7, 0]):
    print("WS")
    elif (seatModulus in [2,5,8,11]):
    print("MS")
    else:
    print("AS")
    return

    ReplyDelete
  7. https://devluper.blogspot.com/2020/11/arrangement-hackerearth-solution.html

    ReplyDelete
  8. how to solve the problem using switch case

    ReplyDelete

Post a Comment

Popular posts from this blog

Android Studio - how to make phone call