/* HDU 2093 考试排名 */ #include <cstdio> #include <string> #include <queue> #include <iostream> using namespace std; struct Node{ string name; int n; int useTime; bool operator<(const Node& rhs) const { //先按从n的值从大到小排序 //我是用rhs在前的方式记忆的,用rhs的项和当前项比较,大就放前面 if (rhs.n > n){ return 1; } else if (rhs.n == n){ //n相等是useTime从小到大排序 if (rhs.useTime < useTime) return 1; else if (rhs.useTime == useTime){ //都相等时按名字从小到大排序 if (rhs.name <= name) return 1; else return 0; } else return 0; } else return 0; } }; priority_queue<Node> q; int main() { int n, m; int t, ch; scanf("%d%d", &n, &m); Node tmp; while (cin >> tmp.name){ tmp.useTime = 0; tmp.n = 0; //输入n道题的成绩 for (int i = 0; i < n; ++i){ scanf("%d", &t); if (t > 0){ ++tmp.n; tmp.useTime += t; if ((ch = getchar()) == '('){ scanf("%d", &t); tmp.useTime += t*m; getchar(); //吃掉 ')' } } }//for(i) q.push(tmp); } while (!q.empty()){ tmp = q.top(); q.pop(); printf("%-10s %2d %4d ", tmp.name.c_str(), tmp.n, tmp.useTime); } return 0; }