#!/usr/koeki/bin/ruby # -*- coding: utf-8 -*- name = [] score = [] score2 = [] n = 0 x = 0 while line=gets if /(\S+),(\d+),(\d+)?,(\d+)?,(\d+)?,(\d+)?,(\d+)?,(\d+)?/ =~ line name[n] = $1 #受験番号 eng = $2.to_i #英語 #他の科目はとりあえず配列otherへ代入 other = [$3.to_i,$4.to_i,$5.to_i,$6.to_i,$7.to_i,$8.to_i] other.sort!.reverse! #得点を大きい順に並び替え score[n]= eng+other[0]+other[1] #上位2科目と英語の3科目の合計をscoreへ score2[n]=score[n] #scoreと同一内容のscore2を作る n += 1 end end score2.sort!.reverse! #score2の得点を大きい順に並び替え while x < 20 number = score.index(score2[x]) #score2の最初の値がscoreの何番目に出てくるか #numberをインデックスとする受験番号,点数の表示 printf("順位%2d位 受験番号%s 合計%4d点\n",x+1,name[number],score[number]) score[number] = 0 #表示した人については点数を0点にすることで検索されないように x += 1 end