diff options
author | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2019-12-15 15:09:13 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2019-12-15 15:09:13 +0700 |
commit | 9e28e4c7b67c54229df11d355047ac8a88ea1817 (patch) | |
tree | 0d9d40db69613c2c49564a3f1987a005d61f4db3 /tht/B/QG-2014/guess.pas | |
parent | 67393f42f41ab92219deb549f711121c4dab845b (diff) | |
download | cp-9e28e4c7b67c54229df11d355047ac8a88ea1817.tar.gz |
Normalize pathname
Diffstat (limited to 'tht/B/QG-2014/guess.pas')
-rw-r--r-- | tht/B/QG-2014/guess.pas | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/tht/B/QG-2014/guess.pas b/tht/B/QG-2014/guess.pas new file mode 100644 index 0000000..af39434 --- /dev/null +++ b/tht/B/QG-2014/guess.pas @@ -0,0 +1,106 @@ +uses dic; + +type + dic_t = array of string; + coun_t = array['a'..'z'] of byte; + +var + f: text; + dict, new_dict: array[0..999999] of string; + chars: array of coun_t; + count: coun_t; + enum: array of record i, n: byte end; + len, new_len: longint; + i, j: byte; + c: char; + + +procedure swapbyte(var x, y: byte); + var + tmp: byte; + + begin + tmp := x; + x := y; + y := tmp + end; + + + +begin + len := 0; + assign(f, 'DIC.DAT'); + reset(f); + while not eof(f) do + begin + readln(f, dict[len]); + inc(len) + end; + close(f); + + setlength(chars, len); + for i := 0 to len - 1 do + begin + for c := 'a' to 'z' do + chars[i][c] := 0; + for c in dict[i] do + inc(chars[i][c]) + end; + for c := 'a' to 'z' do + count[c] := count_char(c); + + new_len := 0; + for i := 0 to len - 1 do + begin + for c := 'a' to '{' do + if chars[i][c] <> count[c] then + break; + if c = '{' then + begin + new_dict[new_len] := dict[i]; + inc(new_len) + end + end; + + setlength(enum, length(new_dict[0])); + for i := 0 to length(enum) - 1 do + begin + enum[i].i := i + 1; + enum[i].n := 0; + for c := 'a' to 'z' do + count[c] := 0; + for j := 0 to new_len - 1 do + inc(count[new_dict[j][i + 1]]); + for c := 'a' to 'z' do + if count[c] > 0 then + inc(enum[i].n) + end; + + for i := 0 to length(enum) - 2 do + for j := i + 1 to length(enum) - 1 do + if enum[i].n < enum[j].n then + begin + swapbyte(enum[i].n, enum[j].n); + swapbyte(enum[i].i, enum[j].i) + end; + + j := 0; + while new_len > 1 do + begin + len := new_len; + for i := 0 to len - 1 do + dict[i] := new_dict[i]; + + c := get_char_at_pos(enum[j].i); + new_len := 0; + for i := 0 to len - 1 do + if dict[i][enum[j].i] = c then + begin + new_dict[new_len] := dict[i]; + inc(new_len) + end; + inc(j) + end; + + answer(new_dict[0]) +end. |