Input
Output
这是一道模拟题,没有什么技巧,仔细分析题目,数组a[]是用来存放0~9的电子管的亮的条数。
输入包含不超过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秒钟。
对于每组数据,输出测试点编号和总耗电量。
Sample InputSTART 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:00Sample Output
Case 1: 9672 Case 2: 478800
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[10]={6,2,5,5,4,5,6,3,7,6};
int fun(int n)
{
int sum=0;
if(n==0)
return 6;
else
{
while(n)
{
sum+=a[n%10];
n/=10;
}
}
return sum;
}
int main()
{
char s1[10],s2[10];
int t1,t2;
int h,m,s;
int score,b[5],t,k=1;
while(~scanf("%s %d:%d:%d",s1,&h,&m,&s))
{
int ans=0;
memset(b,0,sizeof(b));
t1=h*3600+m*60+s;
while(1)
{
scanf("%s %d:%d:%d",s1,&h,&m,&s);
if(s1[0]=='E')
{
t2=h*3600+m*60+s;
ans+=(t2-t)*(fun(b[0])+fun(b[1]));
break;
}
if(s1[0]=='S')
{
scanf("%s %d",s2,&score);
t=h*3600+m*60+s;
ans+=(t-t1)*(fun(b[0])+fun(b[1]));
t1=t;
if(s2[0]=='h')
b[0]+=score;
else
b[1]+=score;
}
}
printf("Case %d: %d\n",k++,ans);
}
return 0;
}