分析
sscanf用法:从一个字符串中读进与指定格式相符的数据
代码
#include<bits/stdc++.h>
using namespace std;
#define MXN 10010
struct student{ char n[15]; int q, t;}s[MXN];
int main(){
int Q, T, cnt = 0, t, err;
char tmp[100];
scanf("%d %d", &Q, &T);
while(scanf("%s", s[cnt+1].n) == 1){
cnt++;
for(int i = 1; i <= Q; i++){
scanf("%s", tmp);
if(tmp[0] != '-' && tmp[0] != '0'){
s[cnt].q++;
if(sscanf(tmp, "%d(%d)", &t, &err) == 2){ // 格式化输入
s[cnt].t += T*err;
}
s[cnt].t += t;
}
}
}
sort(s+1, s+cnt+1, [](student x, student y){
if(x.q == y.q){
if(x.t == y.t) return strcmp(x.n, y.n) < 0;
return x.t < y.t;
}
return x.q > y.q;
});
for(int i = 1; i <= cnt; i++){
printf("%-10s %2d %4d\n",s[i].n, s[i].q, s[i].t);
}
return 0;
}