题目地址:点击打开链接
恶心的打印图像。
慢慢绘制,因为是对称的,画好四分之一再去填充就可以了。
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 150;
char str[maxn][maxn];
int h;
void init()
{
memset(str, 0, sizeof(str));
for(int i = 1; i <= h; i++)
for(int j = 1; j <= h; j++)
str[i][j] = '.';
}
void copy()
{
for(int i = 1; i <= h; i++)
for(int j = 1; j <= h; j++)
{
if(i <= h/2+1 && j > h/2)
str[i][j] = str[i][h+1-j];
if(i > h/2)
str[i][j] = str[h+1-i][j];
}
}
void show()
{
for(int i = 1; i <= h; i++)
printf("%s\n", str[i]+1);
}
int main(void)
{
int n;
while(cin >> n)
{
h = 9+(n-1)*4;
int midx = 5+(n-1)*2;
int midy = midx;
init();
for(int i = midx-2; i <= midx+2; i++) str[i][midy] = '$';
for(int i = midy-2; i <= midy+2; i++) str[midx][i] = '$';
for(int i = 1; i <= n; i++)
{
int x = midx-2*i;
int y = midy-2*(i+1);
for(int j = 0; j <= i*2; j++)
str[x+j][y] = '$';
str[x][y+1] = str[x][y+2] = str[x-1][y+2] = '$';
int x2 = x-2, y2 = y+2;
for(int j = 0; j <= i*2; j++)
str[x2][y2+j] = '$';
}
copy();
show();
}
return 0;
}
历届试题 打印十字图
时间限制:1.0s 内存限制:256.0MB
问题描述
小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示:
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
对方同时也需要在电脑dos窗口中以字符的形式输出该标志,并能任意控制层数。
输入格式
一个正整数 n (n<30) 表示要求打印图形的层数。
输出格式
对应包围层数的该标志。
样例输入1
1
样例输出1
..$$$$$..
..$...$..
$$$.$.$$$
$...$...$
$.$$$$$.$
$...$...$
$$$.$.$$$
..$...$..
..$$$$$..
..$...$..
$$$.$.$$$
$...$...$
$.$$$$$.$
$...$...$
$$$.$.$$$
..$...$..
..$$$$$..
样例输入2
3
样例输出2
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
提示
请仔细观察样例,尤其要注意句点的数量和输出位置。