学习C语言时候最简单的模拟。。
AC代码:
#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
int main(int argc, char const *argv[])
{
int n;
while(cin >> n) {
int a = n /2, b = 1, c = 1;
for(int i = 1; i <= n; ++i) {
if(a >= 1) {
for(int j = 1; j <= a; ++j)
printf("*");
for(int j = 1; j <= b; ++j)
printf("D");
for(int j = 1; j <= a; ++j)
printf("*");
printf("\n");
a -= 1;
b += 2;
}
else if(a == 0) {
for(int j = 1; j <= n; ++j)
printf("D");
printf("\n");
a -= 1;
b -= 2;
}
else {
for(int j = 1; j <= c; ++j)
printf("*");
for(int j = 1; j <= b; ++j)
printf("D");
for(int j = 1; j <= c; ++j)
printf("*");
printf("\n");
c += 1;
b -= 2;
}
}
}
return 0;
}