1016. Phone Bills (25) PAT甲级

传送门

#include<stdio.h>
#include<algorithm>
#include<string.h>

using namespace std;

#define MAX_N 1100


struct Record{
    char name[25];
    int month,d,h,m;
    bool status;
}r[MAX_N],temp;

int toll[25];

int n;

bool cmp(Record a,Record b){
    int m=strcmp(a.name,b.name);
    if(m!=0)    return m<0;
    else if(a.month!=b.month)   return a.month<b.month;
    else if(a.d!=b.d)   return a.d<b.d;
    else if(a.h!=b.h)   return a.h<b.h;
    else    return a.m<b.m;
}

void get_time_money(int left,int right,int &time,int &money){
    temp=r[left];
    while(temp.d<r[right].d||temp.h<r[right].h||temp.m<r[right].m){
        time++;
        money+=toll[temp.h];
        temp.m++;
        if(temp.m>=60){
            temp.m=0;
            temp.h++;
        }
        if(temp.h>=24){
            temp.h=0;
            temp.d++;
        }
    }
}

int main(){
    char sta[16];
    for(int i=0;i<24;i++){
        scanf("%d",&toll[i]);
    }
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s %d:%d:%d:%d",r[i].name,&r[i].month,&r[i].d,&r[i].h,&r[i].m);
        scanf("%s",sta);
        if(strcmp(sta,"on-line")==0){
            r[i].status=true;
        }
        else{
            r[i].status=false;
        }
    }

    sort(r,r+n,cmp);
    int pair_first=0,pair_second,next;
    while(pair_first<n){
        int isNeedPrint=0;
        next=pair_first;
        while(next<n&&strcmp(r[pair_first].name,r[next].name)==0){
            if(isNeedPrint==0&&r[next].status==true){
                isNeedPrint=1;
            }
            else if(isNeedPrint==1&&r[next].status==false){
                isNeedPrint=2;
            }
            next++;
        }
        if(isNeedPrint<2){
            pair_first=next;
            continue;
        }
        int SumOfMoney=0;
        printf("%s %02d\n",r[pair_first].name,r[pair_first].month);
        while(pair_first<next){
            while(pair_first<next-1&&!(r[pair_first].status==true&&r[pair_first+1].status==false)){
                pair_first++;
            }
            pair_second=pair_first+1;

            if(pair_second==next){
                pair_first=next;
                break;
            }
            printf("%02d:%02d:%02d ",r[pair_first].d,r[pair_first].h,r[pair_first].m);
            printf("%02d:%02d:%02d ",r[pair_second].d,r[pair_second].h,r[pair_second].m);
            int time=0,money=0;
            get_time_money(pair_first,pair_second,time,money);
            SumOfMoney+=money;
            printf("%d $%.2f\n",time,money/100.0);
            pair_first=pair_second+1;
        }
        printf("Total amount: $%.2f\n",SumOfMoney/100.0);
    }

}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值