import std.stdio; import std.file; import std.string; import std.conv; import std.windows.charset; struct Word { string word; int complexity; } Word*[][] words; Word*[string] wordReference; void main() { foreach (fn;listdir("", "*-*.*")) { writef("Loading %s... \r", fn); fflush(stdout); int sep1 = find(fn, '-'); int sep2 = find(fn, '.'); string category = fn[0..sep1]; string classification = fn[sep1+1..sep2]; int size = toInt(fn[sep2+1..$]); foreach(line;splitlines(cast(string)read(fn))) if (line.length) { if (line in wordReference) { if (wordReference[line].complexity < size) wordReference[line].complexity = size; } else { if (words.length<=line.length) words.length = line.length+1; auto word = new Word; *word = Word(line, size); words[line.length] ~= word; wordReference[line] = word; } } } writefln("Wordlists loaded. "); while (true) { auto line = strip(readln()); int[256] score; bool[256] garbage; int pos = find(line, ' '); if (pos>0) { foreach (c;line[pos+1..$]) garbage[c] = true; line = line[0..pos]; } foreach (c;line) garbage[c] = true; wordloop: foreach (word;words[line.length]) { foreach (i,c;line) if (c=='_') { if (garbage[word.word[i]]) continue wordloop; } else { if (c!=word.word[i]) continue wordloop; } foreach (i,c;line) if (c=='_') score[word.word[i]] += 100-word.complexity; } struct Match { char c; int score; int opCmp(Match* m) { return m.score-score; } } Match[] matches; foreach (c,s;score[32..128]) if (s) matches ~= Match(c+32, s); matches.sort; string matchString; foreach (ref m;matches) matchString ~= m.c; /*foreach (char c;matchString) if (c<128) writef("%s", c); else writef("?"); writefln;*/ writefln("%s", fromMBSz(toString(matchString.ptr), 1252)); } }