saws #5148(2008/01/03 14:33 GMT) [ ActionScript ] Rating0/0=0.00
ハッシュを利用しました.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
VOTE_ARY = [123, 4, 56, 78] N = 100 class Hash def gen_vote(ary) key = 'a' ary.each{|x| self[key.succ!] = x} end def gen_vote_list keys.each{|key| 2.upto(N){|i| self["#{key}#{i}"] = self[key].quo(i)} } end end votes, counter = Hash.new, Hash.new votes.gen_vote(VOTE_ARY) votes.gen_vote_list votes.keys.sort{|a, b| -1*(votes[a] <=> votes[b])}. map{|x| x.match(/^([a-zA-Z]+)/)[0]}[0..N-1]. each{|key| eval("counter[key]#{counter.has_key?(key) ? '+' : ''}=1")} p counter.values
Rating0/0=0.00-0+
[ reply ]
saws
#5148()
[
ActionScript
]
Rating0/0=0.00
ハッシュを利用しました.
VOTE_ARY = [123, 4, 56, 78] N = 100 class Hash def gen_vote(ary) key = 'a' ary.each{|x| self[key.succ!] = x} end def gen_vote_list keys.each{|key| 2.upto(N){|i| self["#{key}#{i}"] = self[key].quo(i)} } end end votes, counter = Hash.new, Hash.new votes.gen_vote(VOTE_ARY) votes.gen_vote_list votes.keys.sort{|a, b| -1*(votes[a] <=> votes[b])}. map{|x| x.match(/^([a-zA-Z]+)/)[0]}[0..N-1]. each{|key| eval("counter[key]#{counter.has_key?(key) ? '+' : ''}=1")} p counter.valuesRating0/0=0.00-0+
[ reply ]