Hoj 2564 Regional Ranklist

来源:互联网 发布:淘宝无线端店铺活动 编辑:程序博客网 时间:2024/05/29 15:00

题目:http://acm.hit.edu.cn/hoj/problem/view?id=2564

本题有几点需要注意的:

1:字典序排序时不区分大小写

2:数据读入,我从没想过读第二个值时会覆盖掉第一个值,原来是因为我用于读入时间字符串的数组开小了,只开了8个单位,其实至少应有9个字节长度,于是就把表明题号的字符给覆盖掉了。。。失策失策,此生铭记。

3:其余没什么好说的,熟悉一下Regional的排名规则吧。

#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <algorithm>#include <stack>#include <queue>#include <map>#include <string>using namespace std;struct Person{    char name[30];    int problem[9];    int time[9];    int actotal;    Person()    {        memset(problem,0,sizeof(problem));        memset(time,0,sizeof(time));        actotal = 0;    }};map<string ,int> mapping;//计算过去了多少时间int countTimeGo(char time_str[8]){    int min = (time_str[3] - '0')*10 + (time_str[4] - '0');    int sec = (time_str[6] - '0')*10 + (time_str[7] - '0');    int hour =(time_str[0] - '0')*10 + (time_str[1] - '0') - 9;    int total = hour * 3600 + min * 60 + sec;    return total;}int strcmp2(char a[30],char b[30]){    char a1[30],b1[30];    strcpy(a1,a);    strcpy(b1,b);    for(int i=0; i<strlen(a1); i++)    {        if(a1[i]>='A' && a1[i]<='Z')        {            a1[i] = a1[i] +32;        }    }    for(int i=0; i<strlen(b1); i++)    {        if(b1[i]>='A' && b1[i]<='Z')        {            b1[i] = b1[i] +32;        }    }    return strcmp(a1,b1);}bool cmp(Person a,Person b){    int ta = 0;    int tb = 0;    for(int i=0; i<9; i++)    {        ta += a.time[i];        tb += b.time[i];    }    return a.actotal>b.actotal || ( a.actotal == b.actotal && ta<tb) || (a.actotal == b.actotal && ta == tb && strcmp2(a.name,b.name)<0);}int main(){#ifndef ONLINE_JUDGE    freopen("in.txt","r",stdin);#endif    int n,m;    while(scanf(" %d %d",&n,&m)!=EOF)    {        Person p[105];        char prochar;        char time_str[10];//开大点,覆盖了前面的prochar就不好了        char state[5];        char name[30];        mapping.clear();        for(int i=0; i<n; i++)        {            scanf(" %s",&p[i].name);            mapping.insert(make_pair(p[i].name,i));        }        for(int i=0; i<m; i++)        {            getchar();            scanf(" %c %s %s %s",&prochar,time_str,state,name);            int per_num = mapping[name];            int pro_num = prochar-'A';            int timego = countTimeGo(time_str);            if(strcmp(state,"AC") == 0)            {                //没A过                if(p[per_num].problem[pro_num] == 0)                {                    p[per_num].problem[pro_num] = 1;                    p[per_num].time[pro_num] += timego;                    p[per_num].actotal++;                }            }            else            {                if(p[per_num].problem[pro_num] == 0)                {                    p[per_num].time[pro_num] += 20*60;                }            }        }        for(int i=0; i<n; i++)        {            for(int j=0; j<9; j++)            {                if(p[i].problem[j] == 0)                {                    p[i].time[j] = 0;                }            }        }        sort(p,p+n,cmp);        for(int i=0; i<n; i++)        {            printf("%s\n",p[i].name);        }        printf("\n");    }    return 0;}