Seating Arrangement

Akash and Vishal are quite fond of travelling. They mostly travel by railways. They were traveling on 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. WS, MS or AS.

Example:

Input:  n = 18
Output: 19 WS

Approach

C++

#include <bits/stdc++.h>
using namespace std;
int main()
{

    map<intintmp;
    int i = 1j = 12;
    int m = i + 11o = j + 11;
    int cnt = 1;
    while (cnt <= 9 && j > i)
    {
        mp[i] = j;
        mp[j] = i;
        i++;
        j--;
        if (i > j)
        {
            i = m + 1;
            m = m + 12;
            j = o + 1;
            o = o + 12;
            cnt++;
        }
    }

    map<intstringmp1;
    mp1[1] = "WS";
    for (int j = 12j <= 108j += 11)
    {
        mp1[j] = "WS";
        j++;
        if (j <= 108)
            mp1[j] = "WS";
    }
    for (int j = 6j <= 108j += 11)
    {
        mp1[j] = "WS";
        j++;
        if (j <= 108)
            mp1[j] = "WS";
    }
    mp1[2] = "MS";
    for (int j = 11j <= 108j += 9)
    {
        mp1[j] = "MS";
        j += 3;
        if (j <= 108)
            mp1[j] = "MS";
    }
    for (int j = 5j <= 108j += 9)
    {
        mp1[j] = "MS";
        j += 3;
        if (j <= 108)
            mp1[j] = "MS";
    }
    mp1[3] = "AS";
    for (int j = 10j <= 108j += 7)
    {
        mp1[j] = "AS";
        j += 5;
        if (j <= 108)
            mp1[j] = "AS";
    }
    for (int j = 4j <= 108j += 7)
    {
        mp1[j] = "AS";
        j += 5;
        if (j <= 108)
            mp1[j] = "AS";
    }

    int n = 18;

    cout << mp[n] << " " << mp1[n] << "\n";

    return 0;
}


No comments:

Post a Comment