首页 > 代码库 > 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 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputTwilight 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 <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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。