问题描述
小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示:
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
对方同时也需要在电脑dos窗口中以字符的形式输出该标志,并能任意控制层数。
输入格式
一个正整数 n (n<30) 表示要求打印图形的层数。
输出格式
对应包围层数的该标志。
样例输入1
1
样例输出1
..$$$$$..
..$...$..
$$$.$.$$$
$...$...$
$.$$$$$.$
$...$...$
$$$.$.$$$
..$...$..
..$$$$$..
样例输入2
3
样例输出2
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
代码解答:
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
int fun(int i,int j,int n){
if(i>n*2+3) i=n*4+6-i;
if(j>n*2+3) j=n*4+6-j;
if(i<j) {int temp=i;i=j;j=temp;}
if(i<=2&&j<=2) return 0;
if(i%2==1&&j>=i-2) return 1;
if(j%2==1&&j!=i-1) return 1;
return 0;
}
int main()
{
int n;
cin>>n;
int i,j;
for(i=1;i<=n*4+5;i++){
for(j=1;j<=n*4+5;j++){
if(fun(i,j,n)){
cout<<"$";
}else{
cout<<".";
}
}
cout<<endl;
}
return 0;
}