1016 Phone Bills 25 伤心的一道题

1016 Phone Bills 25

题目链接:1016 Phone Bills

debug很久,测试了很多例子,都没问题。。。但只能过测试点0

emo了,我是一坨垃圾

虽然知道,出bug一定是有原因的,但相同的思路,框架相同的代码,经过不同的人写出来差别是如此的大。。。

人与人终究是有高低之分的,lj就是lj

源码

#include <cstdio>
#include <cstring>
#include <string>
#include <deque>
#include <map>
#include <algorithm>
using namespace std;
int charge[25];

class Time
{
public:
    int month, day, hour, minute;
    bool flag;
    char name[30];
    Time() {}
    Time(int M, int d, int h, int m) : month(M), day(d), hour(h), minute(m) {}
    bool operator<(Time another)
    {
        if (strcmp(this->name, another.name) != 0)
            return strcmp(this->name, another.name) < 0;
        else if (this->month != another.month)
            return this->month < another.month;
        else if (this->day != another.day)
            return this->day < another.day;
        else if (this->hour != another.hour)
            return this->hour < another.hour;
        else
            return this->minute < another.minute;
    }
    //     static bool cmp(Time a, Time b)
    //     {
    //         if(strcmp(a.name, b.name) != 0)
    //             return strcmp(a.name, b.name) == -1;
    //         else if(a.month, b.month)
    //             return a.month < b.month;
    //         else if(a.day != b.day)
    //             return a.day < b.day;
    //         else if(a.hour != b.hour)
    //             return a.hour < b.hour;
    //         else
    //             return a.minute < b.minute;
    //     }
    bool operator==(Time another) { return strcmp(this->name, another.name) == 0 && this->month == another.month && this->flag != another.flag; }
    void operator+=(int i)
    {
        int c = (this->hour + i) / 24;
        this->hour = (this->hour + i) % 24;
        this->day += c;
    }
};

class Call
{
public:
    Time start;
    Time end;
    int time;
    double toll;
    bool cmp_clock(Time s, Time e)
    {
        if (s.day != e.day)
            return s.day < e.day;
        else
            return s.hour < e.hour;
    }
    Call(Time &s, Time &e) : start(s), end(e)
    {
        time = (e.day - s.day) * 24 * 60 + (e.hour * 60 + e.minute) - (s.hour * 60 + s.minute);
        // toll = 0.0;
        // Time s_clk(s.month, s.day, s.hour+1, 0);
        // Time e_clk(e.month, e.day, e.hour, 0);
        // double odd;
        // if(cmp_clock(s_clk, e_clk) == false && s_clk.hour == e_clk.hour+1)
        //     odd = charge[s.hour]*(e.minute - s.minute);
        // else
        // {
        //     odd = charge[s.hour]*(60-s.minute) + charge[e.hour]*e.minute;
        // }
        // while(cmp_clock(s_clk, e_clk))
        // {
        //     toll += charge[s_clk.hour]*60;
        //     s_clk+=1;
        // }
        // toll += odd;
        // toll /= 100;
        double tolls = charge[24] * 60 * s.day + charge[s.hour] * s.minute;
        for (int i = 0; i < s.hour; i++)
        {
            tolls += charge[i] * 60;
        }
        double tolle = charge[24] * 60 * e.day + charge[e.hour] * e.minute;
        for (int i = 0; i < e.hour; i++)
        {
            tolle += charge[i] * 60;
        }
        toll = (tolle - tolls) / 100;
    }
};

int main()
{
    for (int i = 0; i < 24; i++)
    {
        scanf("%d", &charge[i]);
        charge[24] += charge[i];
    }
    int N;
    scanf("%d", &N);
    deque<Time> time_axis;
    for (int i = 0; i < N; i++)
    {
        Time tmp;
        char on_off[10];
        scanf("%s %d:%d:%d:%d %s", tmp.name, &tmp.month, &tmp.day, &tmp.hour, &tmp.minute, on_off);
        tmp.flag = strcmp(on_off, "on-line") == 0;
        time_axis.push_back(tmp);
    }
    sort(time_axis.begin(), time_axis.end());

    // debug
    //     for(auto s = time_axis.begin(); s != time_axis.end(); s++)
    //     {
    //         printf("%s %02d:%02d:%02d:%02d %d\n", s->name, s->month, s->day, s->hour, s->minute, (int)s->flag);
    //     }

    map<string, deque<Call>> bills;
    for (int i = 1; i < time_axis.size(); i++)
    {
        if (time_axis[i - 1].flag == true && time_axis[i].flag == false && time_axis[i-1] < time_axis[i])
        {
            Call bill(time_axis[i - 1], time_axis[i]);
            string name = time_axis[i-1].name;
            bills[name].push_back(bill);
        }
    }

    for (auto i = bills.begin(); i != bills.end(); i++)
    {
        int month = i->second[0].start.month;
        printf("%s %02d\n", i->first.c_str(), month);
        double total = 0.0;
        for (auto s = i->second.begin(); s != i->second.end(); s++)
        {
            total += s->toll;
            printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n", s->start.day, s->start.hour, s->start.minute,
                    s->end.day, s->end.hour, s->end.minute, s->time, s->toll);
        }
        printf("Total amount: $%.2f\n", total);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值