hdu2093 考试排名(还需完善)-LMLPHP

hdu2093 考试排名(还需完善)-LMLPHP

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

 #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
struct stu
{
string name;
int time;
int solved;
}S[];
bool cmp(stu a,stu b)
{
return a.solved != b.solved ? a.solved > b.solved:a.time < b.time;
}
int main()
{
int n, m, wa, time, d;
string str;
cin >> n >> m;
d = ;
while (cin >> S[d].name)
{
S[d].time = ;
S[d].solved = ; for (int j = ; j < n;j++)
{
wa = ;
time = ;
cin >> str;
if (str[] == '' || str[] == '-') // 如果没有AC,不处理
continue;
for (int k = ; k < str.length();k++)
{
if(str[k] == '(') // 当遇到括号
{
k++;
while (str[k] != ')') // 记录括号中的WA次数
{
wa = wa * + str[k] - '';
k++;
}
break;
}
else // 还没有遇到括号
{
time = time * + str[k] - '';// 记录本题的耗时
}
}
S[d].solved++;
S[d].time += (time + wa*m);
}
d++;
}
sort(S, S + d, cmp);
for (int i = ; i < d; i++) {
printf("%-10s %2d %4d\n", S[i].name.c_str(), S[i].solved, S[i].time);
}
return ;
}
05-11 11:12