O-超大型LED显示屏

来源:互联网 发布:网络菜市场 编辑:程序博客网 时间:2024/05/17 06:37

这里写图片描述
Input
输入包含不超过100组数据。每组数据第一行为”START hh:mm:ss”,表示比赛开始时刻为hh:mm:ss。最后一行为”END hh:mm:ss”,即比赛结束时刻。二者之间至少会有一个SCORE信息,格式为”SCORE hh:mm:ss team score”,其中team要么是”home”(主场)要么是”guest”(客场), score表示得分,为1,2或者3。这些信息保证按照时间从早到晚的顺序排列,且任意两条SCORE信息的时刻均不相同。比赛开始时间不会早于9:00,结束时间不会晚于同一天的21:00。注意,如果比赛开始时间为09:00:00,结束时间为09:00:01,比赛长度为1秒钟,而不是2秒钟。

Output
对于每组数据,输出测试点编号和总耗电量。

Sample Input
START 09:00:00
SCORE 09:01:05 home 2
SCORE 09:10:07 guest 3
END 09:15:00
START 09:00:00
SCORE 10:00:00 home 1
SCORE 11:00:00 home 1
SCORE 12:00:00 home 1
SCORE 13:00:00 home 1
SCORE 14:00:00 home 1
SCORE 15:00:00 home 1
SCORE 16:00:00 home 1
SCORE 17:00:00 home 1
SCORE 18:00:00 home 1
SCORE 19:00:00 home 1
SCORE 20:00:00 home 1
END 21:00:00
Sample Output
Case 1: 9672
Case 2: 478800
分析:
直接模拟即可,从前这种题真的是自己不敢想的,也许是怕麻烦,也许是代码能力真的差,但是经历了两次课程设计之后也算是摸出了自己的代码风格,把频繁使用的代码部分单独写一个函数,必要函数单独封装在类里,函数模块尽量精简,主函数尽量只调用函数;
代码:

#include<iostream>#include<cstring>#include<cstdio>#include<string>using namespace std;const int d[10]={6,2,5,5,4,5,6,3,7,6};struct node{    int h,m,s;    node(int h=0,int m=0,int s=0):h(h),m(m),s(s){}}pre,now;int tran(const node &pre,const node &now){    int p = pre.s + pre.m*60 + pre.h*3600;    return (now.s + now.m*60 + now.h *3600 - p);}struct Time{    int past_score,sum;    node pre;    Time(){past_score = sum = 0;}    void updata(const int &score,const node &now){        char ch[30]; int tmp = 0;        sprintf(ch,"%d",past_score);        int len = strlen(ch);        for(int i=0;i<len;i++) tmp+=d[ch[i]-'0'];        sum+= tmp*tran(pre,now);        pre = now; past_score += score;    }    void Init(const node& now){pre = now;}    void ANS(int &ans){ans = sum;}};int Case = 0;void print_ans(Time &A,Time &B,node& now){    A.updata(0,now),B.updata(0,now);    int tmp,ans =0;    A.ANS(tmp);    ans+=tmp;    B.ANS(tmp);    ans+=tmp;    printf("Case %d: %d\n",++Case,ans);}int main(){    string str;    while(cin >> str){        Time A,B;        int score;        scanf("%d:%d:%d",&now.h,&now.m,&now.s);        A.Init(now),B.Init(now);        while(cin >> str){            scanf("%d:%d:%d",&now.h,&now.m,&now.s);            if(str == "END"){                print_ans(A,B,now);                break;            }else{                cin >> str >> score;                if(str == "home")A.updata(score,now);                else B.updata(score,now);            }        }    }}
原创粉丝点击