F
来源:互联网 发布:银河历险记3 mac 下载 编辑:程序博客网 时间:2024/05/17 01:08
Today is Children’s Day. Some children ask you to output a big letter ‘N’. ‘N’ is constituted by two vertical linesand one diagonal. Each pixel of this letter is a character orderly. No tail blank is allowed.
For example, this is a big ‘N’ start with ‘a’ and it’s size is 3.
a e
bdf
c g
Your task is to write different ‘N’ from size 3 to size 10. The pixel character used is from ‘a’ to ‘z’ continuously and periodic(‘a’ is reused after ‘z’).
Input
This problem has no input.
Output
Output different ‘N’ from size 3 to size 10. There is no blank line among output.
Sample Output
[pre]
a e
bdf
c g
h n
i mo
jl p
k q
………
r j
[/pre]
Hint
Not all the resultsare listed in the sample. There are just some lines. The ellipsis expresseswhat you should write.
题意:用小写字母从画长度为3的倒N一直画到长度为10的倒N。(长度为 n 的倒N就先记成case n )
先来看看怎么画倒N:
O O
O OO
OO O
O O
对于这个case 4 的倒N,那么我就可以从定义一个数组用来存要输出的字母,然后最上面的开始,先向下移动3次,然后想右上方移动3次,然后在向下移动三次。每次移动的时候要输出的字母序号都+1。(在两个N之间字母序号也要+1)。
这样正好就有三个方向 可以表示为:
(i+1,j+0)
(i-1,j+1)
(i+1,j+0)
然后按着这些方向走,走三次,就可以画出一个倒N。
接着对于每一个case的倒N,存一次输出一次就可以了。
代码如下:
#include<stdio.h>#include<string.h>int main(){ int i,j; char cha[26]={0}; //用来存字母 char a[100][100]={0}; //用来输出字母 int x_move[3]={1,-1,1}; //记录 i 移动的方向 int y_move[3]={0,1,0}; //记录 j 移动的方向 for(i=0; i<26; i++) //存字母 cha[i]=i+'a'; int ca=3; //表示第 case 个倒 N int time=0; //用来存 cha[] 中第 time 个字母 int z; for(ca=3; ca<=10; ca++) { int turn=0; //turn用来控制数组移动的方向 i=0; j=0; while(turn!=3) //转了三次弯以后表示倒 N 已经画完 { for(z=1; z<=ca; z++) //对于每个ca的倒 N 每次转弯需要存 ca 个字母 { a[i][j]=cha[time]; //将第 time 个字母存进 a[][] 中 if(z!=ca) //在倒 N 的最左下和最右上两个地方 数组不移动 { i+=x_move[turn]; j+=y_move[turn]; time++; if(time==26) //cha[]超过 'z' 时返回 'a' time=0; } } turn++; } time++; //为下一个倒 N 的第一个字母做准备 if(time==26) //cha[]超过 'z' 时返回 'a' time=0; int i_,j_; for(i_=0; i_<ca; i_++) //输出倒 N 型字母 { for(j_=0; j_<ca; j_++) { if(a[i_][j_]) printf("%c",a[i_][j_]); else printf(" "); } printf("\n"); } memset(a, 0, sizeof(a)); } return 0;}