A. Little Pony and Crystal Mine

题目链接:https://codeforces.com/contest/454/problem/A
A. Little Pony and Crystal Mine
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.

Examples
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 <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main(){
	int n=0;
	scanf("%d",&n);
	int l=n/2+1,r=n/2-1;
	for(int i=0;i<n;i++){
		if(i<=n/2){
			l--;
			r++;
		}
		else{
			l++;
			r--;
		}
		for(int j=0;j<l;j++)
			printf("*");
		for(int j=l;j<=r;j++)
			printf("D");
		for(int j=r+1;j<n;j++)
			printf("*");
		printf("\n");
	}
	return 0;
}
全部评论

相关推荐

首先讲三个故事,关于牛客的事件一:2024年,牛客上有一对高学历情侣,求职方向与我当时一致,都是嵌入式方向。他们恰好是我的朋友,专业能力和学历背景都很扎实,也因此拿到了不少优质offer。和很多求职者一样,他们把offer情况整理后发在平台上,本意是记录与交流,但很快引发了争议。有声音指责他们“集邮”“不释放名额”,认为这种展示本身就是一种炫耀。最终讨论失控,当事人删除内容,事件也很快被遗忘。事件二:小红书评论区,一条评价获得了不少共鸣:“感觉牛客就是当年那群做题区毕业了开始找工作还收不住那股味,颇有一种从年级第一掉到年纪第二后抱怨考不上大学的味道”,这条评论被水印里这个同学转发到牛客后,评论...
小型域名服务器:当看到别人比自己强的时候,即便这是对方应得的,很多人会也下意识的歪曲解构对方的意图,来消解自己在这本就不存在的比较中输掉的自信,从而平白制造出很多无谓的争论。比如你会在空余时间来写优质好文,而我回家只会暗区突围,那么我就可以作为键盘侠在这里评论你是不是XXXXXXXX。即便我自己都知道这是假的,但只要这没那么容易证伪,那么当你开始回应的时候,脏水就已经泼出去了,后面可能会有更多的人带着情绪来给我点赞,而毫不关注你写的文章内容本身是啥了。
SAGIMA牛马咖啡
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务