#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include <cstring>
#include <map>
#include <cctype>
#define maxm 1010
#define inf 0x3fffffff
using namespace std;
struct Node{
string id;
int mh,d,h,m;
bool flag;
}node[maxm];
int charge[25];
bool cmp(Node a,Node b){
if(a.id!=b.id)return a.id<b.id;
else if(a.d!=b.d)return a.d<b.d;
else if(a.h!=b.h)return a.h<b.h;
else return a.m<b.m;
}
int calmin(Node a,Node b){
return b.d*24*60+b.h*60+b.m-a.d*24*60-a.h*60-a.m;
}
double calmon(Node a,Node b){
int d=a.d,h=a.h,m=a.m;
int total=0;
while(d<b.d||h<b.h||m<b.m){
total+=charge[h];
m++;
if(m==60){
h++;m=0;
}
if(h==24){
d++;h=0;
}
}
return total/100.0;
}
int main() {
for(int i=0;i<24;i++){
cin>>charge[i];
}
int n;
string stemp;
cin>>n;
for(int i=0;i<n;i++){
cin>>node[i].id;
scanf("%d:%d:%d:%d",&node[i].mh,&node[i].d,&node[i].h,&node[i].m);
cin>>stemp;
if(stemp=="on-line")node[i].flag=true;
else node[i].flag=false;
}
sort(node,node+n,cmp);
double total=0;
int r=0,p=0,next;
bool flag=false; //while比for好写多了。。。。逻辑也更清晰
while(r<n){
next=p+1;
stemp=node[r].id;
while(next<n&&node[next].id==stemp){
if(node[p].flag==true&&node[next].flag==false){
if(flag==false){
cout<<node[p].id;
printf(" %02d\n",node[p].mh);
flag=true;
}
printf("%02d:%02d:%02d ",node[p].d,node[p].h,node[p].m);
printf("%02d:%02d:%02d ",node[next].d,node[next].h,node[next].m);
printf("%d $%0.2f\n",calmin(node[p],node[next]),calmon(node[p],node[next]));
total+=calmon(node[p],node[next]);
}
p++;next++;
}
if(flag==true){
printf("Total amount: $%0.2f\n",total);
}
flag=false;
r=p=next;
total=0;
}
// bool flag2=false,flag3=false; //使用for实现的版本,条件判断比较复杂
// for(int i=0;i<n-1;i++){
// if(node[i].id==node[i+1].id){
// if(node[i].flag==true&&node[i+1].flag==false){
// if(flag2==false){
// cout<<node[i].id;
// printf(" %02d\n",node[i].mh);
// flag2=true;
// flag3=true;
// }
// printf("%02d:%02d:%02d ",node[i].d,node[i].h,node[i].m);
// printf("%02d:%02d:%02d ",node[i+1].d,node[i+1].h,node[i+1].m);
// printf("%d $%0.2f\n",calmin(node[i],node[i+1]),calmon(node[i],node[i+1]));
// total+=calmon(node[i],node[i+1]);
// }
// }else if(flag2==true){
// flag2=false;
// printf("Total amount: $%0.2f\n",total);
// total=0;
// flag3=false;
// }
// if(i==n-2&&flag3==true){
// printf("Total amount: $%0.2f\n",total);
// }
// }
return 0;
}
这种题一开始感觉比较复杂,多看看打打就没什么了