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 :

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
Source Code in C:
#include<stdio.h>
int main()
{
int n,t,ch;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
scanf("%d",&n);
ch=n%12;
switch(ch)
{
case 0 : n-=11;
printf("%d WS\n",n);
break;
case 1 : n+=11;
printf("%d WS\n",n);
break;
case 2 : n+=9;
printf("%d MS\n",n);
break;
case 3 : n+=7;
printf("%d AS\n",n);
break;
case 4 : n+=5;
printf("%d AS\n",n);
break;
case 5 : n+=3;
printf("%d MS\n",n);
break;
case 6 : n+=1;
printf("%d WS\n",n);
break;
case 7 : n-=1;
printf("%d WS\n",n);
break;
case 8 : n-=3;
printf("%d MS\n",n);
break;
case 9 : n-=5;
printf("%d AS\n",n);
break;
case 10 : n-=7;
printf("%d AS\n",n);
break;
case 11 : n-=9;
printf("%d MS\n",n);
break;
}
}
return 0;
}
nice!!!
ReplyDeleteexcellent
ReplyDeleteProgram is not applicable on different values of input
ReplyDeleteImpressive!!
ReplyDeleteMind blowing
ReplyDeletewrite comment in java jdk
ReplyDelete