hdu2093 考试排名(还需完善)

 下面代码是借鉴的。好多的知识点等着完善

 1 #include <iostream>
 2 #include <string>
 3 #include <algorithm>
 4 using namespace std;
 5 struct stu
 6 {
 7     string name;
 8     int time;
 9     int solved;
10 }S[10001];
11 bool cmp(stu a,stu b)
12 {
13     return a.solved != b.solved ? a.solved > b.solved:a.time < b.time;
14 }
15 int main()
16 {
17     int n, m, wa, time, d;
18     string str;
19     cin >> n >> m;
20     d = 0;
21     while (cin >> S[d].name)
22     {
23         S[d].time = 0;
24         S[d].solved = 0;
25 
26         for (int j = 0; j < n;j++)
27         {
28             wa = 0;
29             time = 0;
30             cin >> str;
31             if (str[0] == '0' || str[0] == '-')     // 如果没有AC,不处理
32                 continue;
33             for (int k = 0; k < str.length();k++)
34             {
35                 if(str[k] == '(')                   // 当遇到括号
36                 {
37                     k++;
38                     while (str[k] != ')')           // 记录括号中的WA次数
39                     {
40                         wa = wa * 10 + str[k] - '0';
41                         k++;
42                     }
43                     break;
44                 }
45                 else                                // 还没有遇到括号
46                 {
47                     time = time * 10 + str[k] - '0';// 记录本题的耗时
48                 }
49             }
50             S[d].solved++;
51             S[d].time += (time + wa*m);
52         }
53         d++;
54     }
55     sort(S, S + d, cmp);
56     for (int i = 0; i < d; i++) {
57         printf("%-10s %2d %4d
", S[i].name.c_str(), S[i].solved, S[i].time);
58     }
59     return 0;
60 }
原文地址:https://www.cnblogs.com/Strugglinggirl/p/5997377.html