PAT_A1016#Phone Bills
Source:
Description:
Input Specification:
Output Specification:
Sample Input:10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10 10 CYLL 01:01:06:01 on-line CYLL 01:28:16:05 off-line CYJJ 01:01:07:00 off-line CYLL 01:01:08:03 off-line CYJJ 01:01:05:59 on-line aaa 01:01:01:03 on-line aaa 01:02:00:01 on-line CYLL 01:28:15:41 on-line aaa 01:05:02:24 on-line aaa 01:04:23:59 off-line Sample Output:CYJJ 01 01:05:59 01:07:00 61 $12.10 Total amount: $12.10 CYLL 01 01:06:01 01:08:03 122 $24.40 28:15:41 28:16:05 24 $3.85 Total amount: $28.25 aaa 01 02:00:01 04:23:59 4318 $638.80 Total amount: $638.80 Keys:
Code:1 /* 2 Data: 2019-07-17 19:24:07 3 Problem: PAT_A1016#Phone Bills 4 AC: 53:32 5 6 题目大意: 7 统计月度话费账单 8 输入: 9 第一行给出,各小时的话费权重cent/minute 10 第二行给出,通话数N<=1e3 11 接下来N行,name,time,status(on/off) 12 输出: 13 打印各个用户的账单,姓名递增 14 name,month 15 start,end,time,costs 16 total amount 17 */ 18 19 #include<cstdio> 20 #include<vector> 21 #include<string> 22 #include<iostream> 23 #include<algorithm> 24 using namespace std; 25 const int M=1e3+10,H=24; 26 struct node 27 { 28 string name,status; 29 string time; 30 }info[M]; 31 struct mode 32 { 33 int dd,hh,mm; 34 }; 35 int n,w[H]; 36 37 bool cmp(const node &a,const node &b) 38 { 39 if(a.name != b.name) 40 return a.name < b.name; 41 else 42 return a.time < b.time; 43 } 44 45 mode Time(string s) 46 { 47 mode t; 48 t.dd = atoi(s.substr(3,2).c_str()); 49 t.hh = atoi(s.substr(6,2).c_str()); 50 t.mm = atoi(s.substr(9,2).c_str()); 51 return t; 52 } 53 54 int Pay(string s1,string s2,int &time,int &cost) 55 { 56 mode t1 = Time(s1); 57 mode t2 = Time(s2); 58 while(t1.dd!=t2.dd || t1.hh!=t2.hh || t1.mm!=t2.mm) 59 { 60 time++; 61 cost += w[t1.hh]; 62 t1.mm++; 63 if(t1.mm==60) 64 { 65 t1.mm=0; 66 t1.hh++; 67 } 68 if(t1.hh==24) 69 { 70 t1.hh=0; 71 t1.dd++; 72 } 73 } 74 return cost; 75 } 76 77 int main() 78 { 79 #ifdef ONLINE_JUDGE 80 #else 81 freopen("Test.txt","r",stdin); 82 #endif 83 84 for(int i=0; i<H; i++) 85 scanf("%d",&w[i]); 86 scanf("%d",&n); 87 for(int i=0; i<n; i++) 88 cin >> info[i].name >> info[i].time >> info[i].status; 89 sort(info,info+n,cmp); 90 for(int i=1; i<n; i++) 91 { 92 int valid=0,bill=0; 93 while(i<n && info[i-1].name==info[i].name) 94 { 95 int cost=0,time=0; 96 if(info[i-1].status=="on-line"&&info[i].status=="off-line") 97 { 98 if(!valid) cout << info[i].name << " " << info[0].time.substr(0,2) << endl; 99 valid=1; 100 bill += Pay(info[i-1].time,info[i].time,cost); 101 cout << info[i-1].time.substr(3) << " " << info[i].time.substr(3); 102 printf(" %d $%.2fn",1.0*cost/100.0); 103 } 104 i++; 105 } 106 if(valid) printf("Total amount: $%.2fn",1.0*bill/100.0); 107 } 108 109 return 0; 110 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |