Comment detail

あみだくじ (Nested Flatten)

なんの捻りもなく。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
static const char* AMIDA[] = {
    "A B C D E",
    "| | |-| |",
    "|-| | |-|",
    "| |-| |-|",
    "|-| |-| |",
    "|-| | | |",
    NULL,
};

int main(int argc, _TCHAR* argv[])
{
    char szAns[100];
    strcpy(szAns, AMIDA[0]);
    printf("%s\n", AMIDA[0]);

    for (int n = 1; AMIDA[n] != NULL; n++)
    {
        printf("%s\n", AMIDA[n]);

        for (int p = 0; AMIDA[n][p] != '\0'; p++)
        {
            if ((AMIDA[n][p] == '-') && (p > 0))
            {
                char c = szAns[p - 1];
                szAns[p - 1] = szAns[p + 1];
                szAns[p + 1] = c;
            }
        }
    }

    printf("%s\n", szAns);
    return 0;
}

Index

Feed

Other

Link

Pathtraq

loading...