标签:codeforces 实现题
题目链接:http://codeforces.com/problemset/problem/454/A
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.
The only line contains an integer n (3?≤?n?≤?101; n is odd).
Output a crystal of size n.
3
*D* DDD *D*
5
**D** *DDD* DDDDD *DDD* **D**
7
***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