(模拟)打印十字图

  历届试题 打印十字图  

时间限制:1.0s   内存限制:256.0MB

      

问题描述

小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示:

..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..

对方同时也需要在电脑dos窗口中以字符的形式输出该标志,并能任意控制层数。

输入格式

一个正整数 n (n<30) 表示要求打印图形的层数。

输出格式

对应包围层数的该标志。

样例输入1

1

样例输出1

..$$$$$..
..$...$..
$$$.$.$$$
$...$...$
$.$$$$$.$
$...$...$
$$$.$.$$$
..$...$..
..$$$$$..

样例输入2

3

样例输出2

..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..

提示

请仔细观察样例,尤其要注意句点的数量和输出位置。

#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<bitset>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define eps (1e-8)
#define MAX 0x3f3f3f3f
#define u_max 1844674407370955161
#define l_max 9223372036854775807
#define i_max 2147483647
#define re register
#define pushup() tree[rt]=max(tree[rt<<1],tree[rt<<1|1])
#define nth(k,n) nth_element(a,a+k,a+n);  // 将 第K大的放在k位
#define ko() for(int i=2;i<=n;i++) s=(s+k)%i // 约瑟夫
#define ok() v.erase(unique(v.begin(),v.end()),v.end()) // 排序,离散化
#define Catalan C(2n,n)-C(2n,n-1)  (1,2,5,14,42,132,429...) // 卡特兰数
using namespace std;

inline int read(){
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' & c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

typedef long long ll;
const double pi = atan(1.)*4.;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const int M=63;
const int N=1e5+5;

char s[1005][1005];
int a[35],b[35];
void fun(int x,int y,int n){
    int p1=y,p2=y+n-1;
    for(int i=p1;i<=p2;i++) s[x][i]='$';

    for(int i=x;i<(x+3);i++) s[i][p1]=s[i][p2]='$';

    for(int i=p1;i>=(p1-2);i--) s[x+2][i]='$';
    for(int i=p2;i<=(p2+2);i++) s[x+2][i]='$';

    p1=y-2; p2=y+n+1; int xx=x+2;
    for(int i=xx;i<(xx+n);i++)  s[i][p1]=s[i][p2]='$';

    xx+=(n-1);
    for(int i=p1;i<(p1+3);i++) s[xx][i]='$';
    for(int i=p2;i>(p2-3);i--) s[xx][i]='$';;

    p1=y; p2=y+n-1;
    for(int i=xx;i<(xx+3);i++) s[i][p1]=s[i][p2]='$';

    for(int i=p1;i<=p2;i++) s[xx+2][i]='$';
}

void init(){
    a[1]=1;
    for(int i=2;i<=32;i++)
        a[i]=a[i-1]+4;
    b[1]=9;
    for(int i=2;i<=32;i++)
        b[i]=b[i-1]+4;
}
int main(){
    int n;  init();
    scanf("%d",&n);
    for(int i=0;i<=b[n];i++)
        for(int j=0;j<=b[n];j++)
            s[i][j]='.';

    int m=a[n+1];
    int x=1,y=3;
    while(m>=1){
        fun(x,y,m);
        m-=4;
        x+=2;
        y+=2;
    }
    for(int i=1;i<=b[n];i++){
        for(int j=1;j<=b[n];j++)
            printf("%c",s[i][j]);
        printf("\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/black_horse2018/article/details/88741462