Seating Arrangement Problem (HackerEarth) Solution in C#.

This blog is related to the problem statement which I was find in HackerEarth.com for practice test. During problem solving I found this interesting and thought to create blog so as other developer might be find it useful. As C# is my favorite programming language I am creating code into C#.


Problem Statement:-


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








Solution in C#:-

I am pasting complete program here.

using System;
using System.Collections.Generic;

namespace Practise
{
class Program
{
public static void Main()
{

int T = 0, N = 0, rem = 0;

T = int.Parse(Console.ReadLine());

List<int> Nlist = new List<int>();
for (int i = 0; i < T; i++)
{
Nlist.Add(int.Parse(Console.ReadLine()));
}

for (int i = 0; i < Nlist.Count; i++)
{
switch (rem = Nlist[i] % 12)
{
case 1:
Console.WriteLine("{0} {1}", Nlist[i] + 11, "WS");
break;
case 2:
Console.WriteLine("{0} {1}", Nlist[i] + 9, "MS");
break;
case 3:
Console.WriteLine("{0} {1}", Nlist[i] + 7, "AS");
break;
case 4:
Console.WriteLine("{0} {1}", Nlist[i] + 5, "AS");
break;
case 5:
Console.WriteLine("{0} {1}", Nlist[i] + 3, "MS");
break;
case 6:
Console.WriteLine("{0} {1}", Nlist[i] + 1, "WS");
break;
case 7:
Console.WriteLine("{0} {1}", Nlist[i] - 1, "WS");
break;
case 8:
Console.WriteLine("{0} {1}", Nlist[i] - 3, "MS");
break;
case 9:
Console.WriteLine("{0} {1}", Nlist[i] - 5, "AS");
break;
case 10:
Console.WriteLine("{0} {1}", Nlist[i] - 7, "AS");
break;
case 11:
Console.WriteLine("{0} {1}", Nlist[i] - 9, "MS");
break;
case 0:
Console.WriteLine("{0} {1}", Nlist[i] - 11, "WS");
break;
}
}
Console.ReadLine();
}
}
}

Comments