Professional Documents
Culture Documents
Hackerank Challenge 10 Q1
Hackerank Challenge 10 Q1
Problem
Submissions
Leaderboard
Discussions
Input Format
For example, after seats 1A, 2B, and 4C are taken, the display should look like:
1XBCD
2AXCD
3ABCD
4ABXD
5ABCD
6ABCD
7ABCD
Constraints
n>0
Output Format
initial seat arrangements........
1ABCD
2ABCD
3ABCD
4ABCD
5ABCD
6ABCD
7ABCD
enter valid seat no to check(like 1B) or N to end: 2B congrats, your seat is valid.
Reserved for you
updated seat status..........
1ABCD
2AXCD
3ABCD
4ABCD
5ABCD
6ABCD
7ABCD
enter valid seat no to check(like 1B) or N to end: 3C congrats, your seat is valid.
Reserved for you
updated seat status..........
1ABCD
2AXCD
3ABXD
4ABCD
5ABCD
6ABCD
7ABCD
enter valid seat no to check(like 1B) or N to end: 7C congrats, your seat is valid.
Reserved for you
updated seat status..........
1ABCD
2AXCD
3ABXD
4ABCD
5ABCD
6ABCD
7ABXD
Sample Input 0
2B
Sample Output 0
ABCD
AXCD
Sample Input 1
3C
Sample Output 1
ABCD
AXCD
ABXD
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
for(int i=0;i<n;i++)
for(int j=0;j<4;j++)
cout<<a[i][j]<<" ";
cout<<endl;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
char arr[7][4];
int n;
char c;
while(1)
cin>>n;
cin>>c;
if(c=='N')
break;
else
//cout<<"n= "<<n<<endl;
//cout<<"c= "<<c<<endl;
if(n==0)
break;
if(n>0)
if(n<=2)
for(int i=0;i<7;i++)
arr[i][0]='A';
arr[i][1]='B';
arr[i][2]='C';
arr[i][3]='D';
for(int i=0;i<4;i++)
{
//cout<<"arr= "<<arr[n][i]<<endl;
//cout<<"c= "<<c<<endl;
if(arr[n-1][i]==c)
//cout<<"seat allocated"<<endl;
arr[n-1][i]='X';
//cout<<"arrseat= "<<arr[n-1][i]<<endl;
PrintSeats(arr,n);
n=0;
if(n==3)
for(int i=0;i<7;i++)
arr[i][0]='A';
if(i==1)
arr[i][1]='X';
else
arr[i][1]='B';
arr[i][2]='C';
arr[i][3]='D';
for(int i=0;i<4;i++)
//cout<<"arr= "<<arr[n][i]<<endl;
//cout<<"c= "<<c<<endl;
if(arr[n-1][i]==c)
{
//cout<<"seat allocated"<<endl;
arr[n-1][i]='X';
//cout<<"arrseat= "<<arr[n-1][i]<<endl;
PrintSeats(arr,n);
n=0;
return 0;