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 :
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.
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
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
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
Post a Comment