1016. Phone Bills (25)
来源:互联网 发布:塞尔维亚 知乎 编辑:程序博客网 时间:2024/04/29 09:42
1016. Phone Bills (25)
时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueA long-distance telephone company charges its customers by the following rules:
Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a long-distance call, the time will be recorded, and so will be the time when the customer hangs up the phone. Every calendar month, a bill is sent to the customer for each minute called (at a rate determined by the time of day). Your job is to prepare the bills for each month, given a set of phone call records.
Input Specification:
Each input file contains one test case. Each case has two parts: the rate structure, and the phone call records.
The rate structure consists of a line with 24 non-negative integers denoting the toll (cents/minute) from 00:00 - 01:00, the toll from 01:00 - 02:00, and so on for each hour in the day.
The next line contains a positive number N (<= 1000), followed by N lines of records. Each phone call record consists of the name of the customer (string of up to 20 characters without space), the time and date (mm:dd:hh:mm), and the word "on-line" or "off-line".
For each test case, all dates will be within a single month. Each "on-line" record is paired with the chronologically next record for the same customer provided it is an "off-line" record. Any "on-line" records that are not paired with an "off-line" record are ignored, as are "off-line" records not paired with an "on-line" record. It is guaranteed that at least one call is well paired in the input. You may assume that no two records for the same customer have the same time. Times are recorded using a 24-hour clock.
Output Specification:
For each test case, you must print a phone bill for each customer.
Bills must be printed in alphabetical order of customers' names. For each customer, first print in a line the name of the customer and the month of the bill in the format shown by the sample. Then for each time period of a call, print in one line the beginning and ending time and date (dd:hh:mm), the lasting time (in minute) and the charge of the call. The calls must be listed in chronological order. Finally, print the total charge for the month in the format shown by the sample.
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 1010CYLL 01:01:06:01 on-lineCYLL 01:28:16:05 off-lineCYJJ 01:01:07:00 off-lineCYLL 01:01:08:03 off-lineCYJJ 01:01:05:59 on-lineaaa 01:01:01:03 on-lineaaa 01:02:00:01 on-lineCYLL 01:28:15:41 on-lineaaa 01:05:02:24 on-lineaaa 01:04:23:59 off-lineSample Output:CYJJ 0101:05:59 01:07:00 61 $12.10Total amount: $12.10CYLL 0101:06:01 01:08:03 122 $24.4028:15:41 28:16:05 24 $3.85Total amount: $28.25aaa 0102:00:01 04:23:59 4318 $638.80Total amount: $638.80这里月份的测试数据应当没有跨月份的。所以sort里面的比较函数就没有比较月份的了。sort按名字字母顺序、时间排序;接着就看看是不是同一个人。然后最接近的两个记录是不是一个on一个off,如果是,说明通话成功计费,否则不计费这里的头文件比较多#include<string> 这个可以直接一个string idnow ,把char/char* PB[index].id赋给它idnow ,可以string 直接和char/char*比较;#include<string.h> 用于strcmp(char*,char*)比较。↑上面的也可以strcpy(idnow, PB[index].id);
#include<algorithm> sort()函数#include<iomanip> setw(2) << setfill('0')整数设置宽度2不够补零;setiosflags(ios::fixed) << setprecision(2)保留两位小数
查看提交
评测结果
时间 结果 得分 题目 语言 用时(ms) 内存(kB) 用户 7月28日 11:13答案正确251016C++ (g++ 4.7.2)4436datrilla测试点
测试点 结果 用时(ms) 内存(kB) 得分/满分 0答案正确130815/151答案正确13084/42答案正确44363/33答案正确42483/3
#include<iostream> #include<string>#include<string.h>#include<algorithm>#include<iomanip>#define daytime 24using namespace std; struct PhoneBills{ char id[21]; bool on; int month; int dd, hh, mm;};void reaDln(PhoneBills*PB, int N){ int index; char oNoff[9]; for (index = 0; index < N; index++) { cin >> PB[index].id >> PB[index].month >> oNoff[0] >> PB[index].dd >> oNoff[0] >> PB[index].hh >> oNoff[0] >> PB[index].mm >> oNoff; PB[index].on = 0 == strcmp(oNoff, "on-line") ? true : false; }}bool PBcmp(const PhoneBills&A, const PhoneBills&B){ if (0 != strcmp(A.id, B.id)) return strcmp(A.id, B.id) < 0; else if (A.dd != B.dd) return A.dd < B.dd; else if (A.hh != B.hh) return A.hh < B.hh; return A.mm < B.mm;} double zeroToNow(int h, int m, int*cost){ double partsum = 0; int index; for (index = 0; index < h; index++) { partsum += 60 * cost[index]; } partsum += m* cost[index]; return partsum;}int monney(int d, int h, int m, int dd, int hh, int mm, int* cost,double* temp){ int totalminute = 0; totalminute = (dd - d) * 60; (*temp) = cost[24] * totalminute; totalminute = totalminute*24; totalminute += (hh - h) * 60 + mm - m; (*temp) += zeroToNow(hh, mm, cost) - zeroToNow(h, m, cost); return totalminute;}int main(){ int cost[daytime+1]; double temp, sum; int index, N,before,totalminute; string idnow; PhoneBills*PB; for (index = 0, cost[daytime] = 0; index < daytime; index++) { cin >> cost[index]; cost[daytime ] += cost[index]; } cin >> N; PB = new PhoneBills[N]; reaDln(PB, N); sort(PB, PB + N, PBcmp); idnow = PB[0].id; for (index = 1;index < N; index++) { sum = 0; temp = 0; totalminute = 0; for (; idnow == PB[index].id&&index < N; index++) { before = index - 1; if (false == PB[index].on&&true==PB[before].on) { if (0 == sum) { cout << idnow << " " << setw(2)<<setfill('0')<<PB[index].month << endl; } totalminute = monney(PB[before].dd, PB[before].hh,PB[before].mm , PB[index].dd, PB[index].hh, PB[index].mm,cost,&temp); cout << setw(2) << setfill('0') << PB[before].dd << ":" << setw(2) << setfill('0') << PB[before].hh <<":"<< setw(2) << setfill('0') << PB[before].mm << " " << setw(2) << setfill('0') << PB[index].dd << ":" << setw(2) << setfill('0') << PB[index].hh <<":"<< setw(2) << setfill('0') << PB[index].mm << " " << totalminute << " $" << setiosflags(ios::fixed) << setprecision(2) << temp / 100<<endl; sum += temp; } } if (0!=sum) cout << "Total amount: $" << setiosflags(ios::fixed) << setprecision(2) << sum /100<< endl; if (index < N) idnow = PB[index].id; } system("pause"); delete[]PB; return 0;}
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- 1016. Phone Bills (25)
- MVC中Model的设计(刚刚)
- POJ 1064 Cable master
- Android开发中Handler的经典总结
- 多态实现线性表(队列,串,堆栈)
- ubuntu14.04开机自动调节亮度
- 1016. Phone Bills (25)
- jquery的each遍历
- iOS多线程的初步研究(四)-- NSTimer
- 再看看maven--手动创建项目与自动创建项目
- telnet'不是内部或外部命令,也不是可运行的程序或批处理文件
- leetcode之路011 Container With Most Water
- cygwin安装步骤
- Android-软键盘弹出和隐藏
- Android使用ViewPager实现左右循环滑动及轮播效果