题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2074
参考(本题忘记考虑=1的情况、本题答案PE格式错误):https://blog.csdn.net/qq_33557479/article/details/50897492
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int n;
char in,out;
int num=0;
while(scanf("%d %c %c",&n,&in,&out)!=EOF)
{
if(num==1)cout<<endl;
num=1;
if(n==1)
{
cout<<in<<endl;
continue;
}
int m=(n+1)/2;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
if((abs(i-m)==m-1) && (abs(j-m)==m-1))
{
putchar(' ');
}
else
{
for(int k=0; k<=m-1; k++)
{
if(((abs(i-m)==k) && (abs(j-m)<=k))||
((abs(i-m)<=k) && (abs(j-m)==k)))
{
if(k%2==0)putchar(in);
else putchar(out);
}
}
}
}
cout<<endl;
}
}
return 0;
}