题解:简单模拟即可。(如果这也算题解的话...)
代码倒是写的有点长。
#include <iostream>
using namespace std;
int prin(int n)
{
int i=n;
while (i>0)
{
cout <<"O.";
i--;
}
return 11-n;
}
void s_prin(int n)
{
int i=n;
while (i>0)
{
cout <<"#.";
i--;
}
}
int main()
{
int k,n,m,b;
cin >>k;
//first line
cout <<"+------------------------+"<<endl;
if (k-4>0)
{
n=(k-4)%3;
m=(k-4)/3;
//second line
cout <<"|";
if (n)
{
b=prin(m+2);
n--;
}
else b=prin(m+1);
s_prin(b);
cout <<"|D|)"<<endl;
//third line
cout <<"|";
if (n)
{
b=prin(m+2);
n--;
}
else b=prin(m+1);
s_prin(b);
cout <<"|.|"<<endl;
// fourth line
cout <<"|O.......................|"<<endl;
// fivth line
cout <<"|";
b=prin(m+1);
s_prin(b);
cout <<"|.|)"<<endl;
//the last
cout <<"+------------------------+"<<endl;
}
else
{
//second line
cout <<"|";
if (k)
{
b=prin(1);
s_prin(10); k--;
}
else s_prin(11);
cout <<"|D|)"<<endl;
//third line
cout <<"|";
if (k)
{
b=prin(1);
s_prin(10); k--;
}
else s_prin(11);
cout <<"|.|"<<endl;
//fourth line
if (k) { cout <<"|O.......................|"<<endl; k--; }
else cout <<"|#.......................|"<<endl;
//fivth line
cout <<"|";
if (k)
{
b=prin(1);
s_prin(10); k--;
}
else s_prin(11); cout <<"|.|)"<<endl;
cout <<"+------------------------+"<<endl;
}
return 0;
}