小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示:
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
对方同时也需要在电脑dos窗口中以字符的形式输出该标志,并能任意控制层数。
一个正整数 n (n<30) 表示要求打印图形的层数。
对应包围层数的该标志。
1
..$$$$$..
..$...$..
$$$.$.$$$
$...$...$
$.$$$$$.$
$...$...$
$$$.$.$$$
..$...$..
..$$$$$..
3
..$$$$$$$$$$$$$..
..$...........$..
$$$.$$$$$$$$$.$$$
$...$.......$...$
$.$$$.$$$$$.$$$.$
$.$...$...$...$.$
$.$.$$$.$.$$$.$.$
$.$.$...$...$.$.$
$.$.$.$$$$$.$.$.$
$.$.$...$...$.$.$
$.$.$$$.$.$$$.$.$
$.$...$...$...$.$
$.$$$.$$$$$.$$$.$
$...$.......$...$
$$$.$$$$$$$$$.$$$
..$...........$..
..$$$$$$$$$$$$$..
请仔细观察样例,尤其要注意句点的数量和输出位置。
AC的代码:
-
#include <stdio.h>
-
void swap(int *a,int *b)
-
{
-
int temp;
-
temp=*a;
-
*a=*b;
-
*b=temp;
-
}
-
int go(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) swap(&i,&j);
-
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;
-
scanf("%d",&n);
-
int i,j;
-
for(i=1;i<=n*4+5;i++)
-
{
-
for(j=1;j<=n*4+5;j++)
-
{
-
if(go(i,j,n)) printf("$");
-
else
-
printf(".");
-
}
-
printf("\n");
-
}
-
return 0;
-
}
java反射工具类
原文:http://blog.csdn.net/phantomes/article/details/19897949