首页 > 代码库 > Codeforces Round #259 (Div. 2) (简单模拟实现题)

Codeforces Round #259 (Div. 2) (简单模拟实现题)

题目链接:http://codeforces.com/problemset/problem/454/A


A. Little Pony and Crystal Mine
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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?≤?101n 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 <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <climits>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define PI acos(-1.0)
#define INF 0x3fffffff
//typedef long long LL;
//typedef __int64 LL;
int main()
{
    int n;
    int i, j, k;
    while(scanf("%d",&n)!=EOF)
    {
        int t  = n/2;
        int tt = t;
        for(i = 0; i < tt; i++)
        {
            for(j = 0; j < t; j++)
            {
                printf("*");
            }
            for(j = 0; j < n-2*t; j++)
            {
                printf("D");
            }
            for(j = 0; j < t; j++)
            {
                printf("*");
            }
            t--;
            printf("\n");
        }
        for(i = 0 ; i < n; i++)
            printf("D");
        printf("\n");
        for(i = 1; i <= tt; i++)
        {
            for(j = 0; j < i; j++)
            {
                printf("*");
            }
            for(j = 0; j < n-2*i; j++)
            {
                printf("D");
            }
            for(j = 0; j < i; j++)
            {
                printf("*");
            }
            printf("\n");
        }
    }
    return 0;
}