# encoding: Shift_JIS
indata = [
"001YAMADA 080A",
"010YAMAMOTO 090B",
"011YAMAMOTO 090A"
]
s = "16,1,A,13,3,D"
#ary = s.split(',').each_slice(3).to_a
#p ary
sortrec = indata.sort {|a, b|
s.split(',').each_slice(3).inject {|c, k|
i, l, d = k[0].to_i, k[1].to_i, k[2] == 'A' ? 1 : -1
c = (a[i, l] <=> b[i, l]) * d
break c if c.nonzero?
0
}
}
indata.each {|a| p a }
puts " "
sortrec.each {|a| p a }
IyBlbmNvZGluZzogU2hpZnRfSklTCgppbmRhdGEgPSBbCgkiMDAxWUFNQURBICAgIDA4MEEiLAoJIjAxMFlBTUFNT1RPICAwOTBCIiwKCSIwMTFZQU1BTU9UTyAgMDkwQSIKXQpzID0gIjE2LDEsQSwxMywzLEQiCiNhcnkgPSBzLnNwbGl0KCcsJykuZWFjaF9zbGljZSgzKS50b19hCgojcCBhcnkKc29ydHJlYyA9IGluZGF0YS5zb3J0IHt8YSwgYnwKCXMuc3BsaXQoJywnKS5lYWNoX3NsaWNlKDMpLmluamVjdCB7fGMsIGt8CgkJaSwgbCwgZCA9IGtbMF0udG9faSwga1sxXS50b19pLCBrWzJdID09ICdBJyA/IDEgOiAtMQoJCWMgPSAoYVtpLCBsXSA8PT4gYltpLCBsXSkgKiBkCgkJYnJlYWsgYyBpZiBjLm5vbnplcm8/CgkJMAoJfQp9CgppbmRhdGEuZWFjaCB7fGF8IHAgYSB9CnB1dHMgIiAgIgpzb3J0cmVjLmVhY2gge3xhfCBwIGEgfQ==