题目分析:
- 这道题是基础的模拟题。按题模拟,分类讨论。
-
如果现在要输出的地方是这一行的最后一个或者第一个,则输出 |。
-
如果现在要输出的地方是在 行,且不是这一行的最后一个或者第一个,那么则输出 -。
-
如前两条都未成立,即输出 a。
AC 代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int mid=(n+1)/2;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(j==1 || j==n)
{
cout<<"|";
}
else if(i==mid)
{
cout<<"-";
}
else
{
cout<<"a";
}
}
if(i!=n) cout<<endl;
}
return 0;
}