Advertisement
Guest User

Untitled

a guest
May 26th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. rows = gets.chomp.split(' ')
  2.  
  3. x,y = rows[0].to_i,rows[1].to_i
  4.  
  5. field = Array.new(y){ Array.new(x) }
  6.  
  7. #フィールドを配列に代入
  8. #列のループ
  9. y.times{|y|
  10. line = gets.chomp.split(' ')
  11. #行のループ
  12. x.times{|x|
  13. field[y][x] = line[x].to_i;
  14. }
  15. }
  16.  
  17. #爆発処理
  18. y.times{|y|
  19. x.times{|x|
  20. if field[y][x] == 2
  21. #一行上が1なら一行下にずらす
  22. if field[y-1][x] == 1
  23. range = 1..y
  24. range.each{|i|
  25. field[y-(i-1)][x] = field[y-i][x]
  26. }
  27. #一番上の列に0を代入
  28. field[y-y][x] = 0
  29. else
  30. field[y][x] = 0
  31. end
  32. end
  33. }
  34. }
  35.  
  36. #出力
  37. field.each{|line|
  38. puts line.join(' ')
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement