fork(1) download
  1. # encoding: Shift_JIS
  2.  
  3. indata = [
  4. "001YAMADA 080A",
  5. "010YAMAMOTO 090B",
  6. "011YAMAMOTO 090A"
  7. ]
  8. s = "16,1,A,13,3,D"
  9. #ary = s.split(',').each_slice(3).to_a
  10.  
  11. #p ary
  12. sortrec = indata.sort {|a, b|
  13. s.split(',').each_slice(3).inject {|c, k|
  14. i, l, d = k[0].to_i, k[1].to_i, k[2] == 'A' ? 1 : -1
  15. c = (a[i, l] <=> b[i, l]) * d
  16. break c if c.nonzero?
  17. 0
  18. }
  19. }
  20.  
  21. indata.each {|a| p a }
  22. puts " "
  23. sortrec.each {|a| p a }
Success #stdin #stdout 0.01s 7448KB
stdin
Standard input is empty
stdout
"001YAMADA    080A"
"010YAMAMOTO  090B"
"011YAMAMOTO  090A"
  
"011YAMAMOTO  090A"
"010YAMAMOTO  090B"
"001YAMADA    080A"