




This was one of the questions that came in Accenture Japan Test 2021 OA Conducted in an IIT
It was a bit wordy and difficult to understand at first glance, but just if-else logic
My CODE:
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int n; cin>>n;
vector<int> arr(n,0);
int mx = 0;
for(int i=0;i<n;i++){
cin>>arr[i];
if(arr[i]>mx){
mx = arr[i];
}
}
cout<<'+';
//cout<<string(2*n-1, '-')<<endl;
for(int i=0;i<2*n+1;i++){
cout<<'-';
}
cout<<endl;
for(int h=2; h<=mx+2; h++){
cout<<'|';
for(int i=2;i<=2*n+2;i++){
if(i%2==0){
cout<<'.';
}
else{
int j = (i-1)/2;
int l = arr[j-1];
if(h<=l){
cout<<'x';
}
else if(h==l+1){
cout<<'v';
}
else{
cout<<'.';
}
}
}
cout<<endl;
}
cout<<'+';
for(int i=0;i<2*n+1;i++){
cout<<'-';
}
//cout<<string(2*n-1, '-');
return 0;
}