1442: [蓝桥杯][2013年第四届真题]打印十字图
题目描述
历届试题 打印十字图
时间限制:1.0s 内存限制:256.0MB
问题描述
小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示:
..$$$$$$$$$$$$$.. ..$...........$.. $$$.$$$$$$$$$.$$$ $...$.......$...$ $.$$$.$$$$$.$$$.$ $.$...$...$...$.$ $.$.$$$.$.$$$.$.$ $.$.$...$...$.$.$ $.$.$.$$$$$.$.$.$ $.$.$...$...$.$.$ $.$.$$$.$.$$$.$.$ $.$...$...$...$.$ $.$$$.$$$$$.$$$.$ $...$.......$...$ $$$.$$$$$$$$$.$$$ ..$...........$.. ..$$$$$$$$$$$$$..
对方同时也需要在电脑dos窗口中以字符的形式输出该标志,并能任意控制层数。
提示
请仔细观察样例,尤其要注意句点的数量和输出位置。
输入
一个正整数 n (n< 30) 表示要求打印图形的层数。
输出
对应包围层数的该标志。
样例输入
3
样例输出
..$$$$$$$$$$$$$.. ..$...........$.. $$$.$$$$$$$$$.$$$ $...$.......$...$ $.$$$.$$$$$.$$$.$ $.$...$...$...$.$ $.$.$$$.$.$$$.$.$ $.$.$...$...$.$.$ $.$.$.$$$$$.$.$.$ $.$.$...$...$.$.$ $.$.$$$.$.$$$.$.$ $.$...$...$...$.$ $.$$$.$$$$$.$$$.$ $...$.......$...$ $$$.$$$$$$$$$.$$$ ..$...........$.. ..$$$$$$$$$$$$$..
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char map[1010][1010];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int i,j;
int m=1+4*(n+1);
for(i=1;i<=m;i++)
{
for(j=1;j<=m;j++)
map[i][j]='.';
}
int sx,sy,ex,ey;
sx=sy=1;
ex=ey=m;
while(n--)
{
sx+=2;
ex-=2;
for(i=sx;i<=ex;i++)
{
map[sy][i]='$';
map[ey][i]='$';
}
sy+=2;
ey-=2;
for(i=sy;i<=ey;i++)
{
map[i][sx-2]='$';
map[i][ex+2]='$';
}
map[sy-1][sx]='$';
map[sy][sx-1]='$';
map[sy-1][ex]='$';
map[sy][ex+1]='$';
map[ey+1][sx]='$';
map[ey][sx-1]='$';
map[ey+1][ex]='$';
map[ey][ex+1]='$';
map[sx][sy]=map[ex][ey]=map[sx][ey]=map[ex][sy]='$';
}
for(i=sy;i<=ey;i++)
{
map[i][sx+2]='$';
}
for(i=sx;i<=ex;i++)
{
map[sy+2][i]='$';
}
for(i=1;i<=m;i++)
{
for(j=1;j<=m;j++)
{
printf("%c",map[i][j]);
}
printf("\n");
}
}
}