【HDU 4706】【水题】Children's Day

看起来题目很长,其实就用26个英文字母来写N字,数据较小,直接暴力打表也可以的。

或者像下面的代码一样这样写。用a对26取余就可以。很机制的做法。


#include "stdio.h"
#include "string.h"
int main()
{
    int a = 0;
    char c[100][100];
    for(int i = 3;i <= 10;i++)
    {
        for(int j = 0;j < i;j++)
        {
            for(int k = 0;k < i;k++)
                c[j][k] = ' ';
            c[j][i] = 0;
        }
        for(int j = 0;j < i;j++)
        {
            c[j][0] = 'a' + a;
            a = (a+1)%26;
        }
        for(int j = i-2;j > 0;j--)
        {
            c[j][i-1-j] = 'a' + a;
            a = (a+1)%26;
        }
        for(int j = 0;j < i;j++)
        {
            c[j][i-1] = 'a' + a;
            a = (a+1)%26;
        }
        for(int j = 0;j < i;j++)
            printf("%s\n",c[j]);
    }
    
    return 0;
}


你可能感兴趣的:(c,水题)