简单模拟题。
#include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> using namespace std; int cost[30]; int n; struct X { string name; int dd,hh,mm,len,f; }s[2000],ans[2000]; int month; bool flag[2000]; bool cmp(const X&a,const X&b) { if(a.len==b.len) return a.f>b.f; return a.len<b.len; } bool cmp2(const X&a,const X&b) { if(a.name==b.name) return a.len<b.len; return a.name<b.name; } int get(int a,int b) { int sum=0; for(int i=ans[a].len;i<ans[b].len;i++) { int DD=i/(24*60); int HH=(i-DD*24*60)/60; sum=sum+cost[HH]; } return sum; } int main() { for(int i=0;i<24;i++) scanf("%d",&cost[i]); scanf("%d",&n); for(int i=1;i<=n;i++) { cin>>s[i].name; scanf("%d:%d:%d:%d",&month,&s[i].dd,&s[i].hh,&s[i].mm); s[i].len=s[i].dd*24*60+s[i].hh*60+s[i].mm; char op[10]; scanf("%s",op); if(op[1]==‘n‘) s[i].f=1; else s[i].f=0; } memset(flag,0,sizeof flag); sort(s+1,s+1+n,cmp); int tot=0; for(int i=1;i<=n;i++) { if(flag[i]==1) continue; if(s[i].f==0) continue; for(int j=i+1;j<=n;j++) { if(s[i].name==s[j].name) { if(s[j].f==0&&flag[j]==0){ ans[++tot]=s[i]; ans[++tot]=s[j]; flag[i]=1; flag[j]=1; } break; } } } sort(ans+1,ans+1+tot,cmp2); int pos=1; cout<<ans[1].name<<" "; printf("%02d\n",month); printf("%02d:%02d:%02d ",ans[pos].dd,ans[pos].hh,ans[pos].mm); printf("%02d:%02d:%02d ",ans[pos+1].dd,ans[pos+1].hh,ans[pos+1].mm); printf("%d ",ans[pos+1].len-ans[pos].len); printf("$%.2lf\n",1.0*get(1,2)/100); double sum=1.0*get(1,2)/100; pos=pos+2; for(int i=pos;i<=tot;i=i+2) { if(ans[i].name==ans[i-2].name) { printf("%02d:%02d:%02d ",ans[i].dd,ans[i].hh,ans[i].mm); printf("%02d:%02d:%02d ",ans[i+1].dd,ans[i+1].hh,ans[i+1].mm); printf("%d ",ans[i+1].len-ans[i].len); printf("$%.2lf\n",1.0*get(i,i+1)/100); sum=sum+1.0*get(i,i+1)/100; } else { printf("Total amount: $%.2lf\n",sum); cout<<ans[i].name<<" "; printf("%02d\n",month); printf("%02d:%02d:%02d ",ans[i].dd,ans[i].hh,ans[i].mm); printf("%02d:%02d:%02d ",ans[i+1].dd,ans[i+1].hh,ans[i+1].mm); printf("%d ",ans[i+1].len-ans[i].len); printf("$%.2lf\n",1.0*get(i,i+1)/100); sum=1.0*get(i,i+1)/100; } } printf("Total amount: $%.2lf\n",sum); return 0; }
时间: 2024-10-09 02:50:58