HDU 4706 Children's Day(模拟)

题目链接:HDU 4706 Children's Day


用字母 a - z 画 N , 当z画完,z后面接上a

a e
bdf
c g  规模为3
h  n
i mo
jl p
k  q 规模为4

只要画出规模为 3 - 10 的 N 即可 。

做了两次这个题目了 , 每次都是直接用printf 画出来 ,也花不了多少时间偷笑


这次直接贴一个模拟的代码吧,难点在于不好想怎么 先竖着输出 再斜着输出 再竖着输出。

其实只要用字符数组储存要输出的图形,然后将整个字符数组输出就可以了。


【源代码】

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
	char ch[30]="abcdefghijklmnopqrstuvwxyz";
	char map[15][15];
	int cnt = 0;
	for(int i=3;i<=10;i++){
		memset(map,' ',sizeof(map)); //用 空格 初始化 map
	
		for(int j=0;j<i;j++){
			map[j][0] = ch[cnt%26]; //先竖着储存字符
			cnt++;
		}
		for(int j=i-2;j>=1;j--){
			map[j][i-j-1]=ch[cnt%26];  斜着储存字符
			cnt++;
		}
		for(int j=0;j<i;j++){
			map[j][i-1]=ch[cnt%26];  再 竖着储存
			cnt++;
		}
		for(int j=0;j<i;j++){
			for(int k=0;k<i;k++){
				printf("%c",map[j][k]);
			}
			printf("\n");
		}
		
	}
	return 0;
}


posted @ 2015-09-04 19:24  编程菌  阅读(154)  评论(0编辑  收藏  举报