def f( x , a ) x[ 0 ].length.times { |i| if x[ 0 ][ i ] == a then return x[ 1 ][ i ] end } return -1 end x = [ [ 'D' , 'A' , 'E' , 'C' , 'B' ] , [ 70 , 85 , 60 , 45 , 30 ] ] a = 'B' if f( x , a ) != -1 then printf( "%sさんの合計点数は%dです\n" , a , f( x , a ) ) end