Children's Day
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1248 Accepted Submission(s): 799
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.
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').
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]题意:用a到z连续的小写字母打印N形到z之后再从头开始。解析:找到规律,暴力求解,难点就是每一行上打印的字母不是连续的,而是有一定的规律,而且还要注意控制空格。#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <algorithm> using namespace std; char zm[300]; void init() { char ch = 'a'; for(int i = 1; i <= 300; i++) { zm[i] = ch; if(ch == 'z') ch = 'a'; else ch++; } } int main() { init();//打表,将字母按照顺序全部都打出来 int i,j,k,num = 1; for(i = 3; i <= 10; i++) { j = i; int qk = i-2,hk = 0,ff;//控制前面空格和后面空格 for(k = 1; k <= i; k++) { printf("%c",zm[num]);//直接打印每一行的第一个字母 for(int x = 0; x < qk; x++) printf(" "); if(qk == i - 2)//代表第一行,两字母之间没有字母 { printf("%c",zm[num+i+qk]); qk--; num++; printf("\n"); continue; } else if(qk >= 0)//代表了非最后一行,两字母之间有字母 { printf("%c",zm[num+(i-k+1)+qk]); ff = num+(i-k+1)+qk+hk; } for(int x = 0; x < hk; x++) printf(" "); printf("%c",zm[ff+k]); qk--; hk++; num++;//相当于移动行数,因为随着行数的增加,起始字符也在移动 printf("\n"); } if(i == 3)//在打印的这个N形的最左下角开始加,是num增加到下一个N形的左上角的位置。 num += 4; else num = num + 4 + (i - 3) * 2; } return 0; }