3

hdoj 4706 Children's Day

 3 years ago
source link: https://zxs.io/article/175
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

hdoj 4706 Children's Day

2013-09-08 分类:未分类 阅读(4335) 评论(0)

题目意思就是用a-z组成一个N,然后到z后又跳回a,输出宽从3到10的N。

#include <stdio.h>
#include <string.h>
char s[14][15];

int main()
{
    int cnt = 0;
    for (int kase = 3; kase <= 10; kase++)
    {
        memset(s, ' ', sizeof(s));
        for (int i = 1; i <= kase; i++)
        {
            for (int j = 1; j <= kase; j++)
            {
                cnt %= 26;
                if (i == 1 || i == kase)
                {
                    cnt %= 26;
                    s[j][i] = 'a'+cnt;
                    cnt++;
                }
                else
                {
                    if (i == j)
                    {
                        cnt %= 26;
                        s[kase-j+1][i] = 'a'+cnt;
                        cnt++;
                        break;
                    }
                }
            }
        }
        for (int i = 1; i <= kase; i++)
        {
            for (int j = 1; j <= kase; j++)
            {
                printf("%c", s[i][j]);
            }
            puts("");
        }
    }
    return 0;
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK