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[]={,,,,,,,,,};
struct node{
int h,m,s;
node(int h=,int m=,int s=):h(h),m(m),s(s){}
}pre,now; int tran(const node &pre,const node &now){
int p = pre.s + pre.m* + pre.h*;
return (now.s + now.m* + now.h * - p);
} struct Time{
int past_score,sum;
node pre;
Time(){past_score = sum = ;}
void updata(const int &score,const node &now){
char ch[]; int tmp = ;
sprintf(ch,"%d",past_score);
int len = strlen(ch);
for(int i=;i<len;i++) tmp+=d[ch[i]-''];
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 = ;
void print_ans(Time &A,Time &B,node& now){
A.updata(,now),B.updata(,now);
int tmp,ans =;
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);
}
}
}
}

最新文章

  1. pdo的使用
  2. 金融行业的BI应用分析
  3. win7系统下的FTP配置
  4. 01什么是ExtJs?
  5. 4Web Service中的几个重要术语
  6. 简单学ES6 - class
  7. ruby1.8到2.1语法改变
  8. AX 用代码创建FORM动态加控件,重载动态添加的控件的方法。
  9. CodeForces 534C Polycarpus&#39; Dice (数学)
  10. Html学习_style属性应用
  11. thinkphp3.23整合phpexcel
  12. 分析java 嵌套类与内部类
  13. 12.04 ubuntu 更改IP
  14. highcharts使用-拼接数据
  15. Vue 报错[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders
  16. PL/SQl编程 基本语法
  17. go语言开发教程之web项目开发实战
  18. java的toString()及包装类的实现--Integer重点学习
  19. project 2013 工时完成百分比不会自动更新填充
  20. 暂时刷完leetcode的一点小体会

热门文章

  1. LeetCode - 滑动窗口最大值
  2. docker-compose部署ELK(亲测)
  3. asp.net ajax传递Json给aspx.cs后台 webmethod方法传递json
  4. 运行Spark官方提供的例子
  5. vscode Vue格式化HTML标签换行问题
  6. layui select动态添加option
  7. MVC Areas的使用
  8. 自动化应用一键部署卸载&amp;持续构建测试与交付
  9. 如何进行EDM邮件内容的撰写
  10. 服务器控件调用JS函数