这道题太麻烦了,先放这儿,日后再说。。。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 150;
struct player{
char name[20];
int s[4] = {0},ts,ranked,same = 1;
bool isam = false,isdis = false;
}p[maxn];
int t,n;
double total,per[70];
int cmp(player a,player b){
if(a.ts != b.ts) return a.ts < b.ts;
int i = 0;
while(a.name[i] && b.name[i] && a.name[i] == b.name[i]) i++;
return a.name[i] < b.name[i];
}
void readpl(int x){
fgets(p[x].name,20,stdin);
if(p[x].name[strlen(p[x].name)-1] == '*') p[x].isam = true;
char t[20];
fgets(t,12,stdin);
int i,cnt = 0;
for(i = 0;t[i] && t[i] != 'D';i += 3){
p[x].s[cnt++] = (t[i+1] - '0')*10 + t[i+2] - '0';
}
if(t[i] == 'D'){
p[i].isdis = true;
p[i].ts = 1000;
}
}
void prspa(int len){
while(len--) putchar(' ');
}
int main(){
int kase = 0;
scanf("%d",&t);
while(t--){
scanf("\n%lf",&total);
for(int i = 0;i < 70;i++) scanf("%lf",&per[i]);
scanf("%d",&n);
for(int i = 0;i < n;i++) readpl(i);
for(int i = 0;i < n;i++){
if(!p[i].isdis) p[i].ts = p[i].s[0] + p[i].s[1];
}
sort(p,p + n,cmp);
int cnt = 70; //晋级人数
while(p[69].ts == p[cnt].ts) cnt++;
for(int i = 0;i < n;i++){
if(!p[i].isdis) p[i].ts += p[i].s[2] + p[i].s[3];
}
sort(p,p + cnt,cmp);
int cnt2 = 70;
while(cnt2 < cnt && p[69].ts == p[cnt2].ts) cnt2++;
int prets = p[0].ts,ranked = 1,cnt3 = 0;
p[0].ranked = 1;
cnt = 1;
for(int i = 1;i < cnt2;i++){
if(p[i].ts != prets){
prets = p[i].ts;
ranked += cnt;
cnt = cnt3 = 0;
}else{
if(p[i].isam) cnt3++;
cnt++;
}
p[i].ranked = ranked;
}
if(kase++ > 0) putchar('\n');
printf("Player Name Place RDJ RD2 RD3 RD4 TOTAL Money Won\n");
printf("-----------------------------------------------------------------------\n");
for(int i = 0;i < cnt2;i++){
player t = p[i];
printf("%s",t.name);
prspa(21 - strlen(t.name));
printf("%10d",t.ranked);
for(int j = 0;j < 4;j++){
if(t.s[j]) printf("%5d",t.s[j]);
else prspa(5);
}
if(t.ts <= 400) printf("%10d",t.ts);
else{ puts("DQ");prspa(8);}
printf("$%.2lf\n",total*per[t.ranked-1]);
}
}
}