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
import std.stdio;
import std.string;

void main(){
    string[] amida = ["A B C D E",
                      "| | |-| |",
                      "|-| | |-|",
                      "| |-| |-|",
                      "|-| |-| |",
                      "|-| | | |"];

    auto pos = cast(char[])amida[0].dup;
    foreach(s; amida[1..$]){
        foreach(i, c; s[0..($ - 1)]){
            if(c == '-'){
                auto tmp = pos[i - 1];
                pos[i - 1] = pos[i + 1];
                pos[i + 1] = tmp;
            }
        }
    }
    amida ~= cast(string)pos;
    writefln(amida.join("\n"));
}

Index

Feed

Other

Link

Pathtraq

loading...