Comment detail

コード中の文字の頻度分析 (Nested Flatten)

This comment is reply for 6382 crane: プログラムコード中の文字の頻度は言語によ...(コード中の文字の頻度分析). Go to thread root.

出題者です。 こちらで用意していた回答は awk を使ったものでした。一応解説すると、組み込み変数FSを空にし、1行単位の文字毎に連想配列に格納しています。

1
2
3
4
5
6
7
8
9
# 1文字版
BEGIN { FS="" }
{ for (i=1; i<=NF; i++) ht[$i]++}
END { for (c in ht) print ht[c],c }

# 3文字版
BEGIN { FS="" }
{ for (i=1; i<=NF-2; i++) { ht[$i$(i+1)$(i+2)]++}}
END { for (c in ht) print ht[c],c }

Index

Feed

Other

Link

Pathtraq

loading...