problemscpp
A collection of my answers to algorithm problems in c++.
| 函数 | 变量
pat::a::a1016 命名空间参考

1016 Phone Bills 更多...

struct  customer
 
struct  record
 

函数

int main (istream &cin, ostream &cout)
 
 TEST (a1016, case1)
 

变量

const unsigned M = 31 * 1440 + 10
 

详细描述

1016 Phone Bills

函数说明

◆ main()

int pat::a::a1016::main ( istream &  cin,
ostream &  cout 
)

在文件 pat.cpp4445 行定义.

4445 {
4446 map<string, customer> um;
4447 double sum[M] = {};
4448 array<unsigned, 24> cost{};
4449 for(int i = 0; i < cost.size(); i++) {
4450 cin >> cost[i];
4451 }
4452 for(unsigned i = 1; i < M; i++) {
4453 sum[i] = sum[i - 1] + cost[(i - 1) % 1440 / 60] / 100.0;
4454 }
4455 unsigned int n;
4456 cin >> n;
4457 for(unsigned i = 0; i < n; i++) {
4458 string name;
4459 string time;
4460 string online;
4461 cin >> name >> time >> online;
4462 auto r = record(name, time, online);
4463 if(!um.contains(name)) {
4464 um[name] = customer(name);
4465 }
4466 um[name].records.emplace_back(r);
4467 }
4468 for(auto &[name, c]: um) {
4469 sort(c.records.begin(), c.records.end());
4470 for(auto it = c.records.begin(); it != c.records.end();) {
4471 if((*it).online && (it + 1 == c.records.end() || (*(it + 1)).online)) {
4472 it = c.records.erase(it);
4473 } else {
4474 ++it;
4475 }
4476 }
4477 vector<record> new_vec;
4478 bool looking_for_online = true;
4479 for(const auto &record: c.records) {
4480 if(looking_for_online == record.online) {
4481 new_vec.emplace_back(record);
4482 looking_for_online = !looking_for_online;
4483 }
4484 }
4485 c.records = new_vec;
4486 if(!c.records.empty()) {
4487 cout << name << ' ' << setw(2) << setfill('0') << right << c.records[0].month << endl;
4488 double total = 0;
4489 for(int i = 0; i < c.records.size(); i += 2) {
4490 const unsigned t2 = c.records[i + 1].get_minutes();
4491 const unsigned t1 = c.records[i].get_minutes();
4492 const double price = sum[t2] - sum[t1];
4493 total += price;
4494 cout << c.records[i].time.substr(3) << ' ' << c.records[i + 1].time.substr(3) << ' ' << t2 - t1 << " $" << fixed << setprecision(2) << price << endl;
4495 }
4496 cout << "Total amount: $" << fixed << setprecision(2) << total << endl;
4497 }
4498 }
4499 return 0;
4500 }
const unsigned M
Definition: pat.h:807

引用了 M, pat::a::a1016::record::online , 以及 acwing::acwing1929::right.

被这些函数引用 TEST().

◆ TEST()

pat::a::a1016::TEST ( a1016  ,
case1   
)

在文件 pat_test.cpp2089 行定义.

2089 {
2090 istringstream in("10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10\n10\nCYLL 01:01:06:01 on-line\nCYLL 01:28:16:05 off-line\nCYJJ 01:01:07:00 off-line\nCYLL 01:01:08:03 off-line\nCYJJ 01:01:05:59 on-line\naaa 01:01:01:03 on-line\naaa 01:02:00:01 on-line\nCYLL 01:28:15:41 on-line\naaa 01:05:02:24 on-line\naaa 01:04:23:59 off-line\n");
2091 auto out = ostringstream();
2092 main(in, out);
2093 ASSERT_EQ("CYJJ 01\n01:05:59 01:07:00 61 $12.10\nTotal amount: $12.10\nCYLL 01\n01:06:01 01:08:03 122 $24.40\n28:15:41 28:16:05 24 $3.85\nTotal amount: $28.25\naaa 01\n02:00:01 04:23:59 4318 $638.80\nTotal amount: $638.80\n", out.str());
2094 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().

变量说明

◆ M

const unsigned pat::a::a1016::M = 31 * 1440 + 10

在文件 pat.h807 行定义.

被这些函数引用 acwing::acwing1726::main(), pat::a::a1003::main() , 以及 main().