Skip to content

Latest commit

 

History

History
169 lines (155 loc) · 3.44 KB

1016.md

File metadata and controls

169 lines (155 loc) · 3.44 KB

1016

1 Key Points

  1. 不显示total charge=0的用户
  2. 计算total charge可以用整天 - 头 - 尾
  3. 过程比较复杂, 仔细code

2 Answers

#include <cctype>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll;

double toll[24];
struct call {
	string name;
	int month;
	int day;
	int hour;
	int min;
	int time;
	bool line;
} c[1000];

bool cmp(struct call c1, struct call c2) {
	if (c1.name != c2.name) {
		return c1.name < c2.name;
	}
	else {
		return c1.time < c2.time;
	}
}

int main() {
	for (int i = 0; i < 24; i++) {
		cin >> toll[i];
	}
	/*
	for (int i = 0; i < 24; i++) {
		cout << toll[i] << " ";
	}
	cout << endl;
	// */
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c[i].name;
		string s;
		cin >> s;
		c[i].month = (s[0] - '0') * 10 + (s[1] - '0');
		c[i].day = (s[3] - '0') * 10 + (s[4] - '0');
		c[i].hour = (s[6] - '0') * 10 + (s[7] - '0');
		c[i].min = (s[9] - '0') * 10 + (s[10] - '0');
		c[i].time = c[i].day * 24 * 60 + c[i].hour * 60 + c[i].min;
		cin >> s;
		if (s == "on-line") {
			c[i].line = true;
		}
		else {
			c[i].line = false;
		}
	}
	/*
	for (int i = 0; i < n; i++) {
		cout << c[i].name << " " << c[i].day << " " << c[i].hour << " " << c[i].min << " " << c[i].time << " " << c[i].line << endl;
	}
	cout << endl;
	// */
	sort(c, c + n, cmp);
	/*
	for (int i = 0; i < n; i++) {
		cout << c[i].name << " " << c[i].day << " " << c[i].hour << " " << c[i].min << " " << c[i].time << " " << c[i].line << endl;
	}
	cout << endl;
	// */
	// solve
	vector<int> c1;
	vector<int> c2;
	for (int i = 0; i < n - 1; ++i) {
		if (c[i].name == c[i + 1].name && c[i].line == true && c[i + 1].line == false) {
			c1.push_back(i);
			c2.push_back(i + 1);
			++i;
		}
	}
	n = c1.size();

	double costTotal = 0.0;
	double cost1day = 0.0;
	for (int j = 0; j < 24; j++) {
		cost1day += toll[j] * 60.0;
	}
	for (int i = 0; i < n; ++i) {
		if (i == 0 || c[c1[i]].name != c[c1[i - 1]].name) {
			cout << c[c1[i]].name;
			printf(" %02d\n", c[c1[i]].month);
			costTotal = 0.0;
		}

		int p = c1[i], q = c2[i];
		double cost = (c[q].day - c[p].day + 1.0) * cost1day;
		for (int j = 0; j < c[p].hour; j++) {
			cost -= toll[j] * 60.0;
		}
		cost -= c[p].min * toll[c[p].hour];
		for (int j = c[q].hour + 1; j < 24; j++) {
			cost -= toll[j] * 60.0;
		}
		cost -= (60.0 - c[q].min) * toll[c[q].hour];
		cost /= 100;
		costTotal += cost;
		printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2lf\n", c[p].day, c[p].hour, c[p].min, c[q].day, c[q].hour, c[q].min, c[q].time - c[p].time, cost);

		if (i == n - 1 || c[c1[i]].name != c[c1[i + 1]].name) {
			printf("Total amount: $%.2lf\n", costTotal);
		}
	}
	return 0;
}

/*
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
*/

References