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
output
input
output
input
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 ≤ 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; }
相关文章推荐
- Cf 97 Div.2
- cf 753A Santa Claus and Candies
- CFURLCreateStringByAddingPercentEscapes
- CF 757E 数论
- 基于用户的CF
- [CF Gym 100372C] Sergey and array
- [CFNews] AIS Inc. 发布苹果取证产品MacResponse LE
- 【cf 487C】【数论+构造】【根据前缀积取模构造序列】
- CF 85D 五颗线段树
- cf 671D Roads in Yusland
- <cf>Two Problems
- Codeforces Round #397 (Div. 1 + Div. 2 combined) 题解(CF765A,CF765B,CF765C,CF765D,CF765E,CF765F)
- CF 91B
- CF - 779C. Dishonest Sellers 排序+贪心
- <cf>Sysadmin Bob
- CF - 596B. Wilbur and Array 贪心
- 运放稳定性连载16:电容性负载稳定性:噪声增益及 CF(2)
- CF - 766B. Mahmoud and a Triangle - 排序+贪心
- CF Forming Teams
- cf 782B The Meeting Place Cannot Be Changed