//用sort给stl排序
sort(st.begin(),st,end(),cmp);
//用sort给数组排序
sort(a,a+N,cmp);
有2个点段错误?!!!!
这是因为It is guaranteed that at least one call is well paired in the input.
也就说也许有很多人的记录,但是最终一定会有一个人的记录被输出!因此对于每一个人的输出一定要判断ans.size()
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
using namespace std;
map<string,int> name;
struct s{
int flag;
int ti[4];
};
vector <s> rec[1010];
int n;
int fare[24];
bool cmp(s a, s b){
if(a.ti[0]!=b.ti[0]){
return a.ti[0]<b.ti[0];
}else{
if(a.ti[1]!=b.ti[1]){
return a.ti[1]<b.ti[1];
}else{
if(a.ti[2]!=b.ti[2]){
return a.ti[2]<b.ti[2];
}else{
return a.ti[3]<b.ti[3];
}
}
}
}
void cost(s a,s b,int &tt,int &pp){
int prea=a.ti[1],preb=a.ti[2],prec=a.ti[3];
int aa=a.ti[1],bb=a.ti[2]+1,cc=0;
while(1){
if(prea==b.ti[1] && preb==b.ti[2]){
break;
}else{
int tmp=cc-prec+(bb-preb)*60+(aa-prea)*24*60;
pp+=(tmp*fare[preb]);
tt+=tmp;
prea=aa;
preb=bb;
prec=cc;
bb++;
if(bb>=24){
bb=0;
aa++;
}
}
}
int tmp=b.ti[3]-prec;
tt+=tmp;
pp+=(tmp*fare[ b.ti[2] ]);
}
int main(){
freopen("in.txt","r",stdin);
for(int i=0;i<24;i++){
scanf("%d",&fare[i]);
}
scanf("%d",&n);
int cnt=0;
for(int i=0;i<n;i++){
char n[30],ss[10];
int a,b,c,d;
scanf("%s %d:%d:%d:%d %s",n,&a,&b,&c,&d,ss);
s tmp;
tmp.ti[0]=a;
tmp.ti[1]=b;
tmp.ti[2]=c;
tmp.ti[3]=d;
if(ss[1]=='n'){
tmp.flag=0;
}else{
tmp.flag=1;
}
map<string,int>::iterator it=name.find(n);
if(it!=name.end()){
rec[ it->second ].push_back(tmp);
}else{
name[n]=cnt;
rec[cnt].push_back(tmp);
cnt++;
}
}
for(int i=0;i<cnt;i++){
sort(rec[i].begin(),rec[i].end(),cmp);
}
for(map<string,int>::iterator it=name.begin();it!=name.end();it++){
int k=it->second;
vector <s> ans;
for(int i=0;i<rec[k].size()-1;i++){
if(rec[k][i].flag==0 && rec[k][i+1].flag==1){
s sta=rec[k][i];
s en=rec[k][i+1];
ans.push_back(sta);
ans.push_back(en);
}
}
//每个人的记录不易定符合,因此要判断ans.size()
if(ans.size()!=0){
printf("%s %02d\n",it->first.c_str(),ans[0].ti[0]);
double total=0;
for(int i=0;i<ans.size();i+=2){
int tt=0,pp=0;
cost(ans[i],ans[i+1],tt,pp);
double p=(double)pp/100;
printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2lf\n",
ans[i].ti[1],ans[i].ti[2],ans[i].ti[3],
ans[i+1].ti[1],ans[i+1].ti[2],ans[i+1].ti[3],tt,p);
total+=pp;
}
printf("Total amount: $%.2lf\n",total/100);
}
}
return 0;
}