naranja #3679(2007/11/02 20:47 GMT) [ D ] Rating0/0=0.00
12109 個でした。 四字熟語データは重複を除いたものを改行区切りで UTF-8 で words.txt に保存してあります。 Pentium4 3GHz、メモリ 2GB 下では 0.38 秒程度でした。
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 35 36 37 38 39 40 41
import std.stdio; import std.file; import std.string; import std.utf; void main(){ wchar[][][wchar] hash; foreach(word; splitlines(cast(string)read("words.txt"))){ wchar[] convedWord = word.toUTF16(); hash[convedWord[0]] ~= convedWord; } bool[wchar[]] checked; int count; foreach(arr; hash){ foreach(top; arr){ if(top[0] in hash){ foreach(left; hash[top[0]]){ if(!(left in checked) && top[3] in hash){ foreach(right; hash[top[3]]){ if(left[3] in hash && right != top && right != left){ foreach(bottom; hash[left[3]]){ if(bottom[3] == right[3] && bottom[0] != top[3] && bottom != top && bottom != left && bottom != right){ writefln(top); writefln(left[1], " ", right[1]); writefln(left[2], " ", right[2]); writefln(bottom); writefln("-------"); count++; } } } } } } } checked[top] = true; } } writefln(count); }
Rating0/0=0.00-0+
[ reply ]
naranja
#3679()
[
D
]
Rating0/0=0.00
Rating0/0=0.00-0+
[ reply ]