1016. Phone Bills (25)_C

A 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 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 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

参考代码:

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <stdio.h>

using namespace std;

struct Call
{
	string name;
	int month;
	int date;
	int hour;
	int minute;
	int total;
	string status;
};

int charge[24];
vector<Call> all_calls;
vector<Call> format_calls;

bool compare(Call a,Call b)
{
	if(a.name < b.name)
		return 1;
	else if(a.name == b.name && a.total < b.total)
		return 1;
	else
		return 0;
}

void show(Call c)
{
	cout<<c.name<<" ";
	cout<<c.month<<":"<<c.date<<":"<<c.hour<<":"<<c.minute<<" ";
	cout<<c.status<<endl;
}

int chargeByTime(int time)
{
	int hours = time/60;
	int minutes = time%60;
	int money = 0;
	int i;
	for(i = 0;i<hours;i++)
		money += charge[i%24]*60;
	money += charge[i%24]*minutes;
	return money;
}

double calCost(Call s,Call t)
{
	return (double)(chargeByTime(t.total)-chargeByTime(s.total))/100;
}
int calLast(Call s,Call t)
{
	return (t.date-s.date)*24*60+(t.hour-s.hour)*60+(t.minute-s.minute);
}
int main()
{
	for(int i = 0;i<24;i++)
		cin>>charge[i];
	int N;
	cin>>N;
	while(N--)
	{
		Call c;
		cin>>c.name;
		cin>>c.month;
		getchar();
		cin>>c.date;
		getchar();
		cin>>c.hour;
		getchar();
		cin>>c.minute;
		c.total = c.minute + 60*c.hour + 24*60*c.date;
		cin>>c.status;
		all_calls.push_back(c);
	}
	sort(all_calls.begin(),all_calls.end(),compare);
	bool haveonline = false;
	string curname;
	for(int i=0;i<all_calls.size();i++)
	{
		if(haveonline == false && all_calls[i].status =="on-line" )
		{
			format_calls.push_back(all_calls[i]);
			haveonline = true;
			curname = all_calls[i].name;
		}
		else if(haveonline == true && all_calls[i].status =="on-line")
		{
			format_calls.pop_back();
			format_calls.push_back(all_calls[i]);
			haveonline = true;
			curname = all_calls[i].name;
		}
		else if(haveonline == true && all_calls[i].status =="off-line"&&all_calls[i].name ==curname)
		{
			format_calls.push_back(all_calls[i]);
			haveonline = false;
		}
	}
	//the last must be offline
	if((*(format_calls.end()-1)).status == "on-line")
		format_calls.pop_back();
	//output
	double totalcost = 0;
	curname = "";
	for(int i=0;i<format_calls.size();i+=2)
	{
		if(format_calls[i].name != curname)
		{
			if(curname!="")
			{
				printf("Total amount: $%.2f\n",totalcost);
				totalcost = 0;
				printf("%s %02d\n",format_calls[i].name.c_str(),format_calls[i].month);
			}
			else
			{
				printf("%s %02d\n",format_calls[i].name.c_str(),format_calls[i].month);
			}
			curname = format_calls[i].name;
		}
		printf("%02d:%02d:%02d",format_calls[i].date,format_calls[i].hour,format_calls[i].minute);
		printf(" ");
		printf("%02d:%02d:%02d",format_calls[i+1].date,format_calls[i+1].hour,format_calls[i+1].minute);
		printf(" ");
		printf("%d",calLast(format_calls[i],format_calls[i+1]));
		printf(" ");
		printf("$%.2f\n",calCost(format_calls[i],format_calls[i+1]));
		totalcost+=calCost(format_calls[i],format_calls[i+1]);
	}
	printf("Total amount: $%.2f\n",totalcost);
}


 

优化这个sql SELECT count( 1 ) FROM ( SELECT B.ID, B.PURCHASE_REQUEST_ID, B.MATERIAL_ID, B.MATERIAL_CODE, B.MATERIAL_NAME, B.STANDARD, B.MODEL_ID, B.BILL_ROW_ID, B.BILL_NO, BILL_NAME, B.MODEL_CODE, B.MODEL_NAME, B.PARENT_MODEL_ID, B.PARENT_MODEL_CODE, B.PARENT_MODEL_NAME, B.UNIT_CODE, B.UNIT_NAME, B.PURCHASE_TYPE_CODE, CAST( NVL( B.APPLY_NUM, 0 ) AS NUMBER ( 24, 10 ) ) AS APPLY_NUM, CAST( NVL( B.DEAL_NUM, 0 ) AS NUMBER ( 24, 10 ) ) AS DEAL_NUM, CAST( NVL( B.RETURN_NUM, 0 ) AS NUMBER ( 24, 10 ) ) AS RETURN_NUM, B.DEAL_USER_ID, B.DEAL_USER_NAME, CAST( NVL( B.PRICE, 0 ) AS NUMBER ( 24, 10 ) ) AS PRICE, CAST( NVL( B.AMOUNT, 0 ) AS NUMBER ( 24, 10 ) ) AMOUNT, B.IMPLEMENT_CODE, B.IMPLEMENT_NAME, B.IMPLEMENT_INVEST_AMOUNT, B.PURCHASE_MANAGER_ID, B.PURCHASE_MANAGER_NAME, B.PROVIDER_ID, B.PROVIDER_NAME, B.REMARK, B.DELIVER_AREA, B.DELIVER_ADDRESS, B.RECEIVE_PEOPLE, B.RECEIVE_PEOPLE_PHONE, B.ITEM_STATUS, B.COST_CENTER, B.COST_BUDGET_CODE, B.COST_IMPLEMENT_NAME, B.FRAME_CONT_ID, B.FRAME_CONT_CODE, B.FRAME_CONT_NAME, B.DETAIL_CONFIG, B.PURCHASE_CATEGORY_CODE, B.INVOICE_TITLE_CODE, B.INVOICE_SEND_ADDRRSS, B.MATERIAL_REQUEST_ITEM_ID, B.YEAR, B.DELETE_FLAG, B.PROVINCE_CODE, B.REASON, B.PARENT_ITEM_ID, B.FRAME_CONT_ITEM_ID, B.SUB_MATERIAL_REQUEST_ID, B.SUB_MATERIAL_REQUEST_CODE, B.MATERIAL_URL, B.RECOMMEND_PROVIDER_NAMES, C.PURCHASE_REQUEST_CODE, C.PURCHASE_REQUEST_NAME, C.APPLY_TYPE_CODE, C.CREATOR_NAME, C.APPLY_TELEPHONE, C.COMPANY_NAME, C.DEPT_NAME, B.CREATE_TIME, TO_CHAR( B.CREATE_TIME, 'YYYY-MM-DD' ) CREATE_TIME_STR, C.ARRIVE_TIME, C.IS_TO_END, C.MONEY_WAY_CODE, C.OWN, C.APPLY_CATEGORY_CODE, C.manu_Type, C.BILL_ID, MMD.MATERIAL_TYPE_CODE, B.BRANCH_COMPANY_DEAL_USER_ID, B.BRANCH_COMPANY_DEAL_USER_NAME, ( SELECT ORG_NAME FROM ORGANIZATIONS WHERE DELETE_FLAG = '0' AND ORG_CODE = ( SELECT PARENT_COMPANY_NO FROM ORGANIZATIONS WHERE ID = B.MATERIAL_DEPT_ID )) AS MATERIAL_COMPANY_NAME, B.ORIGINAL, B.PROVIDER_PRODUCT_MODEL, B.PROVIDER_PRODUCT_NAME, B.PRODUCT_DESC, B.Back_Flag, CASE WHEN MMD.material_type_code = 'WZ' THEN '1' WHEN MMD.material_type_code = 'FW' THEN '2' ELSE '3' END apply_category_code_item, NVL( C.IS_CARDSYSTEM_REQUEST, '0' ) IS_CARDSYSTEM_REQUEST, B.APPLY_GROUP_AUTHORITES, B.SCIENTIFIC_RESEARCH_ID, B.SCIENTIFIC_RESEARCH_CODE, B.SCIENTIFIC_RESEARCH_NAME, B.PREQUALFY_CODE, nvl( C.IS_QUICK, '0' ) AS IS_QUICK, C.PURCHASE_WAY_CODE, C.PURCHASE_TYPE_CODE PURCHASE_TYPE_CODE_P, C.ORIGINAL_TYPE, C.PURCHASE_REQUEST_BILLS_TYPE, B.IS_FRAME_CONT_MONAD FROM PURCHASE_REQUEST_ITEM B LEFT JOIN PURCHASE_REQUEST C ON B.PURCHASE_REQUEST_ID = C.ID LEFT JOIN MATERIAL_DATA MMD ON MMD.ID = B.MATERIAL_ID AND MMD.DELETE_FLAG = '0' WHERE B.delete_flag = '0' AND B.Item_Status IN ( 1 ) AND NOT EXISTS ( SELECT * FROM purchase_request_item_log pril WHERE B.id = pril.purchase_request_item_id AND pril.lock_status = '1' AND pril.delete_flag = '0' ) AND ( ( c.apply_type_code NOT IN ( '20', '41', '3' ) AND nvl( B.Apply_Num, 0 ) > nvl( B.Deal_Num, 0 )) OR c.apply_type_code IN ( '20', '41', '3' ) ) AND B.Deal_User_Id =: 1 AND C.MONEY_WAY_CODE =: 2 AND C.APPLY_TYPE_CODE =: 3 AND C.PAY_OUT_TYPE_CODE =: 4 AND C.APPLY_CATEGORY_CODE =: 5 AND NVL( C.IS_CARDSYSTEM_REQUEST, '0' ) = : 6 AND NOT EXISTS ( SELECT * FROM purchase_request_item p left join material_province mp ON p.material_id = mp.material_id WHERE p.delete_flag = 0 AND mp.delete_flag = 0 AND mp.material_status = 03 AND mp.org_code = p.province_code AND p.id = B.id ) ORDER BY C.ID, B.ID ASC)
最新发布
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值