您的位置:首页 > 其它

CF 453A . Little Pony and Crystal Mine

2014-08-02 19:12 288 查看
这题是C语言练习题吧=。=,做的时候还bug半天,被自己蠢哭了

Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is
odd; n > 1) is an n × n matrix with a diamond
inscribed into it.

You are given an odd integer n. You need to draw a crystal of size n.
The diamond cells of the matrix should be represented by character "D". All other cells of the matrix should be represented by character "*".
Look at the examples to understand what you need to draw.

Input

The only line contains an integer n (3 ≤ n ≤ 101; n is
odd).

Output

Output a crystal of size n.

Sample test(s)

input
3


output
*D*
DDD
*D*


input
5


output
**D**
*DDD*
DDDDD
*DDD*
**D**


input
7


output
***D***
**DDD**
*DDDDD*
DDDDDDD
*DDDDD*
**DDD**
***D***


上挫码。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
using namespace std;
char mp[110][110];
int n;

int main()
{
    while(cin>>n)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
                mp[i][j]='*';
        }
        for(int i=1;i<=n/2+1;i++)
        {
             int t=2*i-1;
             for(int j=(n-t)/2+1,k=j;j<k+t;j++)
                mp[i][j]='D';
        }
        for(int i=1;i<=n/2+1;i++)
        {
            for(int j=1;j<=n;j++)
                printf("%c",mp[i][j]);
            printf("\n");
        }
        for(int i=n/2;i>=1;i--)
        {
            for(int j=1;j<=n;j++)
                printf("%c",mp[i][j]);
            printf("\n");
        }
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: