fork download
  1. #!/usr/bin/env ruby
  2. data =<<EOS
  3. A市 151598人 189112人
  4. B市 2199815人 2191123人
  5. C町 18895人 16157人
  6. D町 4568人 4881人
  7. E村 2120人 1988人
  8. EOS
  9. puts "市町村\t人口増減率"
  10. data.each_line{|e|
  11. e.split.tap{|city, x, y|
  12. puts "#{city}\t#{((y.to_f - x.to_f) / x.to_f * 100).round 1}%"
  13. }
  14. }
  15.  
Success #stdin #stdout 0.01s 6380KB
stdin
Standard input is empty
stdout
市町村	人口増減率
A市	24.7%
B市	-0.4%
C町	-14.5%
D町	6.9%
E村	-6.2%