很久没写模拟题了,,写的很蠢
马一下,待整理。。。ZZZ
#include<bits/stdc++.h>
#define FI first
#define SE second
using namespace std;
typedef long long ll;
typedef pair<string, string> P;
const int maxn = 100 + 7;
/*
分析:
CYLL 01:01:06:01 on-line
CYLL 01:01:08:03 off-line
2 * 60 + 2 = 122 * X = 24.40
6 59 1180
7 60 1200
8 3 60
CYLL 01:28:15:41 on-line
CYLL 01:28:16:05 off-line
CYJJ 01:01:05:59 on-line
CYJJ 01:01:07:00 off-line
aaa 01:01:01:03 on-line
aaa 01:02:00:01 on-line
aaa 01:04:23:59 off-line
aaa 01:05:02:24 on-line
*/
int a[maxn];
int n, m;
map<string, vector<P> > mp;
struct node{
string na, tm, tp;
}x[1007];
bool cmp(node a, node b) {
if(a.na == b.na)
return a.tm < b.tm;
else return a.na < b.na;
}
double work(string s1, string s2) {
cout << s1 << " " << s2;
int cnt = 0;
double res = 0;
int d1 = ( (s1[0] - '0')*10 + (s1[1] - '0') );
int h1 = ( (s1[3] - '0')*10 + (s1[4] - '0') );
int m1 = ( (s1[6] - '0')*10 + (s1[7] - '0') );
int d2 = ( (s2[0] - '0')*10 + (s2[1] - '0') );
int h2 = ( (s2[3] - '0')*10 + (s2[4] - '0') );
int m2 = ( (s2[6] - '0')*10 + (s2[7] - '0') );
if((d1 == d2) && (h1 == h2)) {
cnt += (m2 - m1);
res += (cnt * a[h1]);
cout << " " << cnt << " $";
printf("%.2f\n", res/100.0);
return res;
}
else if(d1 == d2) {
if(m1 > 0) {
cnt += (60 - m1);
res += ((60 - m1) * a[h1]);
h1++;
if(h1 == 24) {
h1 = 0;
d1++;
}
}
cnt += m2;
res += (m2 * a[h2]);
h2--;
if(h2 == -1) {
h2 = 23;
d2--;
}
for(int i = h1; i <= h2; ++i) {
cnt += 60;
res += (60 * a[i]);
}
cout << " " << cnt << " $";
printf("%.2f\n", res/100.0);
return res;
}
else {
if(m1 > 0) {
cnt += (60 - m1);
res += ((60 - m1) * a[h1]);
h1++;
if(h1 == 24) {
h1 = 0;
d1++;
}
}
cnt += m2;
res += (m2 * a[h2]);
h2--;
if(h2 == -1) {
h2 = 23;
d2--;
}
if(d1 == d2) {
for(int i = h1; i <= h2; ++i) {
cnt += 60;
res += (60 * a[i]);
}
}
else if(d1 < d2) {
d1++;
for(int i = h1; i <= 23; ++i) {
cnt += 60;
res += (60 * a[i]);
}
d2--;
for(int i = 0; i <= h2; ++i) {
cnt += 60;
res += (60 * a[i]);
}
for(int i = d1; i <= d2; ++i) {
cnt += (24 * 60);
res += (60 * m);
}
}
cout << " " << cnt << " $";
printf("%.2f\n", res/100.0);
return res;
}
}
void solve(string na) {
sort(mp[na].begin(), mp[na].end());
double sum = 0;
for(int i = 0; i < mp[na].size()-1; ++i) {
if(mp[na][i].SE == "on-line" && mp[na][i+1].SE == "off-line") {
sum += work(mp[na][i].FI.substr(3, 8), mp[na][i+1].FI.substr(3, 8));
}
}
printf("Total amount: $%.2f\n", sum/100.0);
}
int main() {
m = 0;
for(int i = 0; i <= 23; ++i) {
scanf("%d", &a[i]);
m += a[i];
}
scanf("%d", &n);
string na, tm, tp;
for(int i = 1; i <= n; ++i) {
cin >> x[i].na >> x[i].tm >> x[i].tp;
//mp[na].push_back(make_pair(tm, tp));
}
sort(x+1, x+1+n, cmp);
for(int i = 1; i < n; ++i) {
if((x[i].na == x[i+1].na) && (x[i].tp == "on-line" && x[i+1].tp == "off-line")) {
mp[x[i].na].push_back(make_pair(x[i].tm, x[i].tp));
mp[x[i+1].na].push_back(make_pair(x[i+1].tm, x[i+1].tp));
}
}
for(auto i : mp) {
cout << i.FI ;
cout << " " << (i.SE)[0].FI[0];
cout << i.SE[0].FI[1] << endl;
solve(i.FI);
}
return 0;
}