Skip to main content

Seating Arrangement

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 A













SOLUTION


using System;

public class Test
{
public static void Main()
{
int T = Convert.ToInt32(Console.ReadLine());
for(int i=0;i<T;i++)
{
int SeatNo = Convert.ToInt32(Console.ReadLine());
CalculateSeatTypeAndSeatFacingTheSeatNo(SeatNo);
}
}
public static void CalculateSeatTypeAndSeatFacingTheSeatNo(int SeatNo)
{
int Quotient = SeatNo/6;
int Remainder = SeatNo%6;
if(SeatNoIsWS(SeatNo,Quotient,Remainder))
{
  return;
}
else if(SeatNoIsMS(SeatNo,Quotient,Remainder))
{
return;
}
else if(SeatNoIsAS(SeatNo,Quotient,Remainder))
{
return;
}
}
public static bool SeatNoIsWS(int SeatNo,int Quotient,int Remainder)
{
int SeatFacing;
if((Quotient%2==0||Quotient==0)&&(Remainder==1 || Remainder==0))
{
if(Remainder==0)
{
SeatFacing=SeatNo-11;
Console.WriteLine("{0} WS",SeatFacing);
return true;
}
else
{
SeatFacing=SeatNo+11;
Console.WriteLine("{0} WS",SeatFacing);
return true;
}
}
else if((Quotient%2==1)&&(Remainder==1 || Remainder==0))
{
    if(Remainder==0)
{
SeatFacing=SeatNo+1;
Console.WriteLine("{0} WS",SeatFacing);
return true;
}
else
{
SeatFacing=SeatNo-1;
Console.WriteLine("{0} WS",SeatFacing);
return true;
}
}
else
{
return false;
}
}
public static bool SeatNoIsMS(int SeatNo,int Quotient,int Remainder)
{
int SeatFacing;
if((Quotient%2==0||Quotient==0)&&(Remainder==2 || Remainder==5))
{
if(Remainder==2)
{
SeatFacing=SeatNo+9;
Console.WriteLine("{0} MS",SeatFacing);
return true;
}
else
{
SeatFacing=SeatNo+3;
Console.WriteLine("{0} MS",SeatFacing);
return true;
}
}
else if((Quotient%2==1)&&(Remainder==2 || Remainder==5))
{
    if(Remainder==2)
{
SeatFacing=SeatNo-3;
Console.WriteLine("{0} MS",SeatFacing);
return true;
}
else
{
SeatFacing=SeatNo-9;
Console.WriteLine("{0} MS",SeatFacing);
return true;
}
}
else
{
return false;
}
}
public static bool SeatNoIsAS(int SeatNo,int Quotient,int Remainder)
{
int SeatFacing;
if((Quotient%2==0||Quotient==0)&&(Remainder==3 || Remainder==4))
{
if(Remainder==3)
{
SeatFacing=SeatNo+7;
Console.WriteLine("{0} AS",SeatFacing);
return true;
}
else
{
SeatFacing=SeatNo+5;
Console.WriteLine("{0} AS",SeatFacing);
return true;
}
}
else if((Quotient%2==1)&&(Remainder==3 || Remainder==4))
{
    if(Remainder==3)
{
SeatFacing=SeatNo-5;
Console.WriteLine("{0} AS",SeatFacing);
return true;
}
else
{
SeatFacing=SeatNo-7;
Console.WriteLine("{0} AS",SeatFacing);
return true;
}
}
else
{
return false;
}
}
}

Comments

Popular posts from this blog

Print word pattern - odd letters - beginner's code

1. Print the word with odd letters as P M R A O R G O R R A P M Solution: using System; public class Test { public static void Main() { string text = Console.ReadLine(); int n=text.Length; Pattern print = new Pattern (); print.XPattern(text,n); } } public class Pattern { public void XPattern(string text,int n) { char[] textarray = text.ToCharArray(); int reverseprinter = n-1; int middleLetter = n/2; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i==j && j!=middleLetter) { Console.Write(textarray[j]); } else if(j==reverseprinter) { Console.Write(textarray[reverseprinter]); reverseprinter--; } else { Console.Write("*"); } } Console.WriteLine(); } } } OUTPUT Please Enter text: INPUT : program p m r a o r g o r r a p m

GRANDSON PROBLEM

https://www.geeksforgeeks.org/zoho-interview-set-1-campus/ Given a two dimensional array of string like <”luke”, “shaw”> <”wayne”, “rooney”> <”rooney”, “ronaldo”> <”shaw”, “rooney”> Where the first string is “child”, second string is “Father”. And given “ronaldo” we have to find his no of grandchildren Here “ronaldo” has 2 grandchildren. So our output should be 2. SOLUTION using System; public class Test { public static void Main() { var noOfInputs = Console.ReadLine(); int noOfInputLines = Convert.ToInt32(noOfInputs); string[,] FatherSonArray= new String[noOfInputLines,noOfInputLines]; for(int father=0;father<noOfInputLines;father++) { for(int son=0;son<2;son++) { FatherSonArray[father,son] = Console.ReadLine(); } }     Console.WriteLine("No of grandchildrens:");     string GrandFather = Console.ReadLine();     int NoOfGrandSons=0;     Console.WriteLine(GrandFather);     s

BEGINNER's ALPHABET PALINDROME

PRINT ALPHABET PALINDROMIC PYRAMID USING C# using System; public class Test {       public static void Main()       {             var number = Console.ReadLine();             int n = Convert.ToInt32(number);             Pattern print = new Pattern();             print.PrintPalindromePattern(n);       } } public class Pattern {       public void PrintPalindromePattern(int n)       {             int dummy = 1;             char letter = 'A';             int reversepalindrome;             char letteraftereachIteration ='A';             char reverseletter ='A';             for(int i=1;i<=n;i++)             {                     reversepalindrome = i-1;                   for(int j=1;j<=dummy;j++)                   {                         if(j<=i)                         {                         Console.Write(letter++);                         }                         else                         {