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

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

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

 1 #include<set>  
 2 #include<map>  
 3 #include<queue>  
 4 #include<algorithm>  
 5 #include<iostream>
 6 #include<cstdio>
 7 #include<vector>
 8 #include<string>  
 9 #include<string.h>  
10 using namespace std;
11 typedef long long LL;
12 const int INF = 0x7FFFFFFF;
13 const int maxn = 1e3 + 10;
14 double f[maxn];
15 int n, x;
16 char ss[maxn];
17 
18 struct point
19 {
20     string s;
21     int a, b, c, d, f;
22     void read()
23     {
24         cin >> s;
25         scanf("%d:%d:%d:%d", &a, &b, &c, &d);
26         scanf("%s", ss);
27         if (ss[1] == 'n')f = 0; else f = 1;
28     }
29     bool operator<(const point &x)const
30     {
31         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;
32     }
33     bool operator==(const point &x)const
34     {
35         return b == x.b&&c == x.c&&d == x.d;
36     }
37 }a[maxn];
38 
39 double putout(point x, point y)
40 {
41     double ans = 0;
42     int cnt = 0;
43     point u = x;
44     while (true)
45     {
46         ans += f[u.c]; u.d += 1;
47         u.c += u.d / 60;    u.d %= 60;
48         u.b += u.c / 24;    u.c %= 24;
49         cnt++;  if (u == y) break;
50     }
51     printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2lf\n", x.b, x.c, x.d, y.b, y.c, y.d, cnt, ans);
52     return ans;
53 }
54 
55 int main()
56 {
57     for (int i = 0; i < 24; i++)scanf("%d", &x), f[i] = x / 100.0;
58     scanf("%d", &n);
59     for (int i = 0; i < n; i++)a[i].read();
60     sort(a, a + n);
61     for (int i = 0, j; i < n; i = j)
62     {
63         int flag = 0, y = a[i].f;
64         for (j = i + 1; a[j].s == a[i].s; j++)
65         {
66             if (!y&&a[j].f){ flag = 1; break; }
67             else y = a[j].f;
68         }
69         if (flag)
70         {
71             cout << a[i].s;
72             printf(" %02d\n", a[i].a);
73             point x = a[i];
74             double ans = 0;
75             for (j = i + 1; a[j].s == a[i].s; j++)
76             {
77                 if (!x.f&&a[j].f)ans += putout(x, a[j]);
78                 x = a[j];
79             }
80             printf("Total amount: $%.2lf\n", ans);
81         }
82     }
83     return 0;
84 }

 

posted @ 2016-11-19 01:06  demianzhang  阅读(386)  评论(0编辑  收藏  举报