HDU-2093

#include<iostream>
#include <stdio.h> 
#include <math.h>
#include <string.h>
#include <algorithm>
#define LL long long
#define GG int 
#define For(i, j, k) for(int i=j; i<=k; i++)
#define Dow(i, j, k) for(int i=j; i>=k; i--)
using namespace std;
const int N = 10011; 
int n,m;
struct node {
    char name[20];
    int cnt;
    int score;
}stu[N];
bool cmp(node x,node y) {
    if(x.cnt!=y.cnt) return x.cnt>y.cnt;
    else if(x.score!=y.score) return x.score<y.score;
    else return strcmp(x.name,y.name)<0;
}
int main() {
    while(~scanf("%d%d",&n,&m)){
        int t=0;
        char ch[10];
        while(scanf("%s",stu[t].name)!=EOF){
            stu[t].cnt=0;stu[t].score=0;
            for(int i=0;i<n;i++){
                scanf("%s",ch);
                if(ch[0]=='-') continue;        
                if(strcmp(ch,"0")==0) continue;     
                stu[t].cnt++;   
                int j,tmp=0;
                for(j=0;j<strlen(ch);j++){
                    if(ch[j]=='(') break;
                    tmp=tmp*10+ch[j]-'0';
                }
                stu[t].score+=tmp;
                tmp=0;
                if(j<strlen(ch)){       
                    for(int k=j+1;k<strlen(ch)-1;k++){
                        tmp=tmp*10+ch[k]-'0';
                    }
                }
                stu[t].score+=tmp*m;
            }
            t++;
        }
        sort(stu,stu+t,cmp);                                                                            
		for(int i=0;i<t;i++)                                                                         
		    printf("%-10s%3d%5d\n",stu[i].name,stu[i].cnt,stu[i].score);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值