首页 > ACM题库 > HDU-杭电 > HDU 4706-Children’s Day-字符串-[解题报告]HOJ
2015
09-17

HDU 4706-Children’s Day-字符串-[解题报告]HOJ

Children’s Day

问题描述 :

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’).

输入:

This problem has no input.

输出:

This problem has no input.

样例输出:

[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.

字符串处理

先输出第一列,然后输出对角线上的,最后输出最后一列上的。

不能用char定义数组,要用int,不然会出现负数。

AC代码:

#include <stdio.h>
#include <string.h>

int main() {
    int a[12][30][30];
    int i,j,k;
    int z = 97;
    for(i=3; i<=10; i++) {
        for(j=0; j<i; j++) {
            a[i][j][0] = z;
            z++;
            if(z==123)
                z = 97;
        }
        for(j=i-2,k=1; j>=0,k<i; j--,k++) {
            a[i][j][k] = z;
            z++;
            if(z==123)
                z = 97;
        }
        for(j=1; j<i; j++) {
            a[i][j][k-1] = z;
            z++;
            if(z==123)
                z = 97;
        }
    }
    for(i=3; i<=10; i++) {
        for(j=0; j<i; j++) {
            for(k=0; k<i; k++) {
                if(a[i][j][k]>=97 && a[i][j][k]<=122)
                    printf("%c", a[i][j][k]);
                else
                    printf(" ");
            }
            puts("");
        }
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

参考:http://blog.csdn.net/chuck_0430/article/details/11482533