卡到12號的一道題目TAT
阿新 • • 發佈:2019-01-13
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int toll[27]; struct record{ char name[22]; int mm,dd,hh,mmm; char s[22]; }rec[1100]; bool cmp(record a,record b) { if(strcmp(a.name,b.name) != 0) return strcmp(a.name,b.name) < 0; else if(a.mm != b.mm) return a.mm < b.mm; else if(a.dd != b.dd) return a.dd < b.dd; else if(a.hh != b.hh) return a.hh < b.hh; else return a.mmm < b.mmm; } int tim(record a,record b,float & total) { int sum = 0; int dd=a.dd,hh=a.hh,mmm=a.mmm; while(dd !=b.dd||hh != b.hh || mmm != b.mmm) { mmm ++; sum++; total += toll[hh]; if(mmm == 60) { mmm = 0; hh++; } if(hh == 24) { hh = 0; dd++; } } total/= 100; return sum; } int main() { for(int i = 0; i < 24; i++) { scanf("%d",&toll[i]); } int n; scanf("%d",&n); for(int i = 0; i < n; i++) { scanf("%s %d:%d:%d:%d %s",rec[i].name,&rec[i].mm,&rec[i].dd,&rec[i].hh,&rec[i].mmm,rec[i].s); } sort(rec,rec+n,cmp); int now = 0,next; float T = 0; while(now < n-1) { bool flag = false; next = now; while(next < n && strcmp(rec[now].name,rec[next].name) == 0) next++; for(int i = now; i < next-1; i++) { if(rec[i].s[1] == 'n' && rec[i+1].s[1] == 'f') { flag = true; break; } } if(now < n && flag) printf("%s %02d\n",rec[now].name,rec[now].mm); for(int i = now; i < next-1; i++) { if(rec[i].s[1] == 'n' && rec[i+1].s[1] == 'f') { float total = 0; int time = tim(rec[i],rec[i+1],total); printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n",rec[i].dd,rec[i].hh,rec[i].mmm,rec[i+1].dd,rec[i+1].hh,rec[i+1].mmm,time,total); T += total; } } if(T) printf("Total amount: $%.2f\n",T); T = 0; now = next; } return 0; }