ACM-简单题之Children's Day——hdu4706

Children's Day
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 646 Accepted Submission(s): 421

Problem Description
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
b d f
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.


这是一道简单的按要求输出的题目,就是输出一个N,

从3X3到10X10

在本上画一画,不难发现,可以用循环打出表格,

比如4X4的:

①先从0,0→1,0→2,0→3,0

②从3,0(之前打过,不需要打)→2,1→1,2→0,3(给后面③打)

③从0,3→1,3→2,3→3,3

所以4X4的 ①,③循环四次,而②只需要循环2次,因为第一个和第四个都在①、③循环中出现


这样,这道题就搞定了,

你可以建立一个3维数组,来存储然后打出来,也可以像我这样做一个,打出来一个。

要注意一点,字母从a到z,z后面还是a,一直循环,每个N之间没有空行。


恩,代码:

// Children's day

#include <iostream>
#include <string.h>
using namespace std;
char map[11][11];

int main()
{
	char a='a';
	int i,j,k,x,y;
	for(i=3;i<=10;++i)
	{
		// 初始化表格
		memset(map,0,sizeof(map));

		// 第一个循环
		for(j=0;j<i;++j)
		{
			if(a>'z')	a-=26;
			map[j][0]=a++;
		}
		//第二个循环
		x=i-1,y=0;
		for(j=1;j<=i-2;++j)
		{
			if(a>'z')	a-=26;
			map[x+(-1)*j][y+1*j]=a++;
		}
		//第三个循环
		for(j=0;j<i;++j)
		{
			if(a>'z')	a-=26;
			map[j][i-1]=a++;
		}	
		// 打印出来表格
		for(j=0;j<i;++j)
		{
			for(k=0;k<i;++k)
			{
				if(map[j][k]==0)	cout<<" ";
				else	cout<<map[j][k];
			}
			cout<<endl;
		}		
	}

	return 0;
}

然后呢,这道题,因为数据量不算太大,只是7个N,所以暴力也是可以有的,

我没写,只是在网上找了一个,感觉真心强大,7个printf搞定了。。。

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    printf("a e\nbdf\nc g\n");
    printf("h  n\ni mo\njl p\nk  q\n");
    printf("r   z\ns  ya\nt x b\nuw  c\nv   d\n");
    printf("e    o\nf   np\ng  m q\nh l  r\nik   s\nj    t\n");
    printf("u     g\nv    fh\nw   e i\nx  d  j\ny c   k\nzb    l\na     m\n");
    printf("n      b\no     ac\np    z d\nq   y  e\nr  x   f\ns w    g\ntv     h\nu      i\n");
    printf("j       z\nk      ya\nl     x b\nm    w  c\nn   v   d\no  u    e\np t     f\nqs      g\nr       h\n");
    printf("i        a\nj       zb\nk      y c\nl     x  d\nm    w   e\nn   v    f\no  u     g\np t      h\nqs       i\nr        j\n");

    return 0;
}

暴力代码转载自: http://blog.csdn.net/libin56842/article/details/11491791


你可能感兴趣的:(ACM,day,简单题,Childrens,hdu4706)