标签:hpuoj1293
8 20 Smith -1 -16 8 0 0 120 39 0 John 116 -2 11 0 0 82 55(1) 0 Josephus 72(3) 126 10 -3 0 47 21(2) -2 Bush 0 -1 -8 0 0 0 0 0 Alice -2 67(2) 13 -1 0 133 79(1) -1 Bob 0 0 57(5) 0 0 168 -7 0
Josephus 5 376 John 4 284 Alice 4 352 Smith 3 167 Bob 2 325 Bush 0 0
#include <stdio.h> #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; struct Node { string name; int sol_num, time_use; }; vector<Node> stu; bool cmp(Node a, Node b) { if (a.sol_num == b.sol_num) { if (a.time_use == b.time_use) return a.name.compare(b.name) < 0; return a.time_use < b.time_use; } return a.sol_num > b.sol_num; } int main() { // freopen("stdin.txt", "r", stdin); string name, buf; Node tmp; int prob_num, time_pen, time_p, pos, tmp2, tmp3, sol_num; scanf("%d%d", &prob_num, &time_pen); while (cin >> name) { time_p = sol_num = 0; for (int i = 0; i < prob_num; ++i) { cin >> buf; if (buf[0] == '-' || buf[0] == '0') continue; sscanf(buf.c_str(), "%d", &tmp2); pos = buf.find('('); if (pos != string::npos) { sscanf(buf.c_str() + pos + 1, "%d", &tmp3); tmp2 += tmp3 * time_pen; } time_p += tmp2; ++sol_num; } tmp.name = name; tmp.sol_num = sol_num; tmp.time_use = time_p; stu.push_back(tmp); } sort(stu.begin(), stu.end(), cmp); for (vector<Node>::iterator it = stu.begin(); it != stu.end(); ++it) { printf("%-10s %2d %4d\n", (it->name).c_str(), it->sol_num, it->time_use); } return 0; }
标签:hpuoj1293
原文地址:http://blog.csdn.net/chang_mu/article/details/42747745