AOJ 0124 League Match Score Sheet
問題
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0124
解法
ソートするだけ
”勝ち点が同点の場合は入力順に出力してください。”を読み間違えて1WA
入力順を記録するための値をpairに持つと便利
#include <string> #include <iostream> #include <algorithm> using namespace std; typedef pair<int, string> NAME; typedef pair<int, NAME > P; const int MAX_N = 10; P team[MAX_N]; int main(){ int n; bool f = true; while(cin >> n){ if(n == 0) break; if(f) f = false; else cout << endl; for(int i = 0; i < n; i++){ int a, b, c; string name; cin >> name >> a >> b >> c; team[i] = P(3 * a + c, NAME(n-i,name)); } sort(team, team + n); reverse(team, team + n); for(int i = 0; i < n; i++){ cout << team[i].second.second << "," << team[i].first << endl; } } return 0; }