Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arr = gets.chomp.split.map(&:to_i)
- dist = Array.new(10)
- # 頻度
- # 配列初期化
- dist.each_with_index do |d, index|
- if d.nil?
- dist[index] = 0
- end
- end
- # 頻度算出
- arr.each do |d|
- dist[d] += 1
- end
- # 出力
- dist.each do |d|
- print format("%2d ", d)
- end
- puts ''
- # 中央値
- # 頻度一覧から最大頻度算出
- max = -1
- dist.each do |d|
- if d > max
- max = d
- end
- end
- # 最大頻度
- sum = 0
- count = 0
- dist.each do |d|
- if max == d
- sum += dist[p]
- count += 1
- end
- end
- # 最大頻度の合計の平均が頻度
- p sum / count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement