Answer
#include<iostream>
#include <string>
using namespace std;
int main()
{
int n,w,h,i,j,len;
string str;
bool f=0;
while (cin>>n)
{
h=n*2+3;
w=n+2;
cin>>str;
if(f)
cout<<endl;
f=1;
len=str.size();
for(i=1;i<=h;i++)
{
for(j=0;j<len;j++)
{
if(((str[j]=='L' && j==len-1) && i!=h) || ((str[j]=='2' && i>(h+1)/2 && i<h) && j==len-1))
cout<<"*";
else
if((str[j]=='J' && i!=h) || (str[j]=='2' && i>1 && i<(h+1)/2) || (str[j]=='9' && i>(h+1)/2 && i<h))
cout<<string(w-1,' ')+'*';
else
if((str[j]=='L' && i!=h &&j!=len-1) || (str[j]=='2' && i>(h+1)/2 && i<h))
cout<<'*'+string(w-1,' ');
else
if(((str[j]!='J' ||str[j]!='L' ) &&i==1) || (i==h) || ((str[j]=='2' || str[j]=='9') && i==(h+1)/2))
cout<<string(w,'*');
else
if((str[j]=='0' && (i!=1 || i!=h)) || (str[j]=='9' && i>1 && i<(h+1)/2))
cout<<'*'+string(w-2,' ')+'*';
if(j<len-1)
cout<<" ";
}
cout<<endl;
}
}
return 0;
}