Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. arr = gets.chomp.split.map(&:to_i)
  2.  
  3. dist = Array.new(10)
  4.  
  5. # 頻度
  6.  
  7. # 配列初期化
  8. dist.each_with_index do |d, index|
  9. if d.nil?
  10. dist[index] = 0
  11. end
  12. end
  13.  
  14. # 頻度算出
  15. arr.each do |d|
  16. dist[d] += 1
  17. end
  18.  
  19. # 出力
  20. dist.each do |d|
  21. print format("%2d ", d)
  22. end
  23.  
  24. puts ''
  25.  
  26. # 中央値
  27.  
  28. # 頻度一覧から最大頻度算出
  29. max = -1
  30. dist.each do |d|
  31. if d > max
  32. max = d
  33. end
  34. end
  35.  
  36. # 最大頻度
  37. sum = 0
  38. count = 0
  39. dist.each do |d|
  40. if max == d
  41. sum += dist[p]
  42. count += 1
  43. end
  44. end
  45.  
  46. # 最大頻度の合計の平均が頻度
  47. p sum / count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement