Comment detail

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

いろいろ試したところ

  • 圧倒的にスペースが多い
  • アルファベットの頻度分布に割と近いが、その中でも'i' 'n' 't'がやや多いようだ
  • 記号は'.' ';' '=' '(' ')'が多いが、10位以内にはめったに入らない

という感じでした。

 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
using System;
using System.Collections.Generic;
using System.Text;

class Program
{
  static void Main(string[] args)
  {
    args = new string[] { "-utf-8" };
    if (args.Length > 0 && args[0][0] == '-')
    {
      Console.InputEncoding
        = Encoding.GetEncoding(args[0].Substring(1));
    }
    Dictionary<char, int> table = new Dictionary<char, int>();
    string line = null;
    while ((line = Console.ReadLine()) != null)
    {
      foreach (char c in line)
      {
        table[c] = table.ContainsKey(c) ? table[c] + 1 : 1;
      }
    }
    foreach (char c in table.Keys)
    {
      Console.WriteLine("\"{0}\",{1}", c, table[c]);
    }
  }
}

Index

Feed

Other

Link

Pathtraq

loading...