码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-08-02 20:59:54      阅读:306      评论:0      收藏:0      [点我收藏+]

标签:codeforces   实现题   

题目链接: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;
}


Codeforces Round #259 (Div. 2) (简单模拟实现题),布布扣,bubuko.com

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

标签:codeforces   实现题   

原文地址:http://blog.csdn.net/u012860063/article/details/38350635

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!