本博客为博主处女贴 如有问题欢迎指出
--------------------------------------------------------------------------------
虽然不太可能 但是如有转载 请注明出处
Help C5 | ||||||
| ||||||
Description | ||||||
Hello, I’m Sea5, and you can call me C5 instead. I want a program which can sign my name automatically. And my brothers, C0, C1, C2, C3, C4, C6, C7, C8, each of them wants one as well. Can you help us? | ||||||
Input | ||||||
First line is the number of test cases T(T<=8). T lines follow, each line includes an integer N(N<=7), and you should help C(N) to sign his name. | ||||||
Output | ||||||
C0’s signature is ‘C’. When you draw C(N)’s name, you should print the name using C(N-1)’s name as its element, and using the following format to draw it. *XX X** *XX (X is the element, * is blank space) And please don’t print extra spaces at the end of line. For example, C1’s name should be *CC *CC C C** *CC But not *CC (I use * to show you where are spaces.) | ||||||
Sample Input | ||||||
3 | ||||||
Sample Output | ||||||
C |
本类型题其实就是模版体 比赛的时候有模版还是很好做的 (其实没有模版也不难)
最主要的是格式 对输出图形空格的格式 以及没两组输出后又没有空格等
对不同的图行 只要找到相应的位置不断的递归就可以了
其实也可以先把所有的图形都打印下来 然后在选取部分输出就好了
附本题代码
#include<cstdio> //分形问题递归打印解决
#include<cstring>
#include<iostream>
using namespace std;
char a[3000][3000]; //注意数组的大小 不然存不下图形 会RE
int mypow(int d)
{
int ans=1;
for(int i=1;i<=d;i++)
ans*=3;
return ans;
}
void dfs(int cur,int x,int y)
{
if(cur==1)
{
a[x][y]='C';
return ;
}
int s=mypow(cur-2);
dfs(cur-1,x+s,y);//这些按照格式来就好
dfs(cur-1,x,y+2*s);
dfs(cur-1,x,y+s);
dfs(cur-1,x+2*s,y+s);
dfs(cur-1,x+2*s,y+2*s);
}
int main(void)
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
n++;
memset(a,' ',sizeof(a));
dfs(n,1,1);
int s=mypow(n-1);
for(int i=0;i<=s;i++) //先把最大的边界找到
a[i][s+1]='\0';
for(int i=0;i<=s;i++)//其实格式可以每行从后往前来把每个编程\0遇到不是空格就停止
{
for(int j=s+1;j>=0;j--)
{
if(a[i][j]=='C'){a[i][j+1]='\0';break;}
}
}
for(int i=1;i<=s;i++)
printf("%s\n",a[i]+1);//a[i]+1 就是从a[1]开始输出
}
return 0;
}