PAT A 1016. Phone Bills (25)【模拟】

时间:2022-01-22 05:06:20

题目:https://www.patest.cn/contests/pat-a-practise/1016

思路:用结构体存储,按照名字和日期排序,然后先判断是否有效,然后输出,时间加减直接暴力即可

 #include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<string.h>
using namespace std;
typedef long long LL;
const int INF = 0x7FFFFFFF;
const int maxn = 1e3 + ;
double f[maxn];
int n, x;
char ss[maxn]; struct point
{
string s;
int a, b, c, d, f;
void read()
{
cin >> s;
scanf("%d:%d:%d:%d", &a, &b, &c, &d);
scanf("%s", ss);
if (ss[] == 'n')f = ; else f = ;
}
bool operator<(const point &x)const
{
return s == x.s ? a == x.a ? b == x.b ? c == x.c ? d < x.d : c < x.c : b < x.b : a < x.a : s < x.s;
}
bool operator==(const point &x)const
{
return b == x.b&&c == x.c&&d == x.d;
}
}a[maxn]; double putout(point x, point y)
{
double ans = ;
int cnt = ;
point u = x;
while (true)
{
ans += f[u.c]; u.d += ;
u.c += u.d / ; u.d %= ;
u.b += u.c / ; u.c %= ;
cnt++; if (u == y) break;
}
printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2lf\n", x.b, x.c, x.d, y.b, y.c, y.d, cnt, ans);
return ans;
} int main()
{
for (int i = ; i < ; i++)scanf("%d", &x), f[i] = x / 100.0;
scanf("%d", &n);
for (int i = ; i < n; i++)a[i].read();
sort(a, a + n);
for (int i = , j; i < n; i = j)
{
int flag = , y = a[i].f;
for (j = i + ; a[j].s == a[i].s; j++)
{
if (!y&&a[j].f){ flag = ; break; }
else y = a[j].f;
}
if (flag)
{
cout << a[i].s;
printf(" %02d\n", a[i].a);
point x = a[i];
double ans = ;
for (j = i + ; a[j].s == a[i].s; j++)
{
if (!x.f&&a[j].f)ans += putout(x, a[j]);
x = a[j];
}
printf("Total amount: $%.2lf\n", ans);
}
}
return ;
}