1016. Phone Bills (25)

来源:互联网 发布:汉密尔顿 知乎 喜剧 编辑:程序博客网 时间:2024/05/20 18:18

这题我感觉略复杂,hold不住,直接上浅蓝大神的代码。

#include<cstdio>  #include<string>  #include<cstring>  #include<vector>  #include<iostream>  #include<queue>  #include<algorithm>  using namespace std;  typedef long long LL;  const int INF = 0x7FFFFFFF;  const int maxn = 1e3 + 10;  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[1] == 'n') f = 0; else f = 1;      }      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 = 0;      int cnt = 0;      point u = x;      while (true)      {          ans += f[u.c]; u.d += 1;              u.c += u.d / 60;    u.d %= 60;          u.b += u.c / 24;    u.c %= 24;          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 = 0; i < 24; i++) scanf("%d", &x), f[i] = x / 100.0;      scanf("%d", &n);      for (int i = 0; i < n; i++) a[i].read();      sort(a, a + n);      for (int i = 0, j; i < n; i = j)      {          int flag = 0, y = a[i].f;          for (j = i + 1; a[j].s == a[i].s; j++)          {              if (!y&&a[j].f) { flag = 1; break; }              else y = a[j].f;          }          if (flag)          {              cout << a[i].s;              printf(" %02d\n", a[i].a);              point x = a[i];              double ans = 0;              for (j = i + 1; 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 0;  }  



0 0
原创粉丝点击