输入包含不超过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秒钟。
对于每组数据,输出测试点编号和总耗电量。
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
Case 1: 9672
Case 2: 478800
模拟题,按照题意一步步敲下来就行了。我是在数字线段那里打了个表。
#include <stdio.h> int table[10]={6,2,5,5,4,5,6,3,7,6}; char opt[20],team[20]; int getcnt(int number) { int cnt=0; do { if(number==0) return 6; else cnt+=table[number%10]; }while(number/=10); return cnt; } int main() { int i=1; int guest=0,home=0; long long sum=0; int h=0,m=0,s=0; int nh=0,nm=0,ns=0; int score=0; while(scanf("%s",opt)>0) { if(opt[1]=='T') { scanf("%d:%d:%d",&h,&m,&s); continue; } if(opt[1]=='C') { scanf("%d:%d:%d",&nh,&nm,&ns); scanf("%s",team); scanf("%d",&score); if(team[0]=='h') { long long t=(long long)nh*3600+nm*60+ns-h*3600-m*60-s; long long s2=(long long)getcnt(home)+getcnt(guest); sum+=t*s2; home+=score; h=nh; m=nm; s=ns; } if(team[0]=='g') { long long t=(long long)nh*3600+nm*60+ns-h*3600-m*60-s; long long s2=(long long)getcnt(home)+getcnt(guest); sum+=t*s2; guest+=score; h=nh,m=nm,s=ns; } continue; } if(opt[1]=='N') { scanf("%d:%d:%d",&nh,&nm,&ns); long long t=(long long)nh*3600+nm*60+ns-h*3600-m*60-s; long long s2=(long long)getcnt(home)+getcnt(guest); sum+=t*s2; printf("Case %d: %lld\n",i++,sum); guest=0,home=0; sum=0; h=0,m=0,s=0; nh=0,nm=0,ns=0; score=0; continue; } } return 0; } /************************************************************** Problem: 1507 User: lizhaowei213 Language: C++ Result: Accepted Time:4 ms Memory:964 kb ****************************************************************/