PAT (Advanced Level) 1016. Phone Bills (25)

简单模拟题。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
using namespace std;

int cost[30];
int n;
struct X
{
    string name;
    int dd,hh,mm,len,f;
}s[2000],ans[2000];
int month;
bool flag[2000];

bool cmp(const X&a,const X&b)
{
    if(a.len==b.len) return a.f>b.f;
    return a.len<b.len;
}

bool cmp2(const X&a,const X&b)
{
    if(a.name==b.name) return a.len<b.len;
    return a.name<b.name;
}

int get(int a,int b)
{
    int sum=0;

    for(int i=ans[a].len;i<ans[b].len;i++)
    {
        int DD=i/(24*60);
        int HH=(i-DD*24*60)/60;
        sum=sum+cost[HH];
    }
    return sum;
}

int main()
{
    for(int i=0;i<24;i++) scanf("%d",&cost[i]);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        cin>>s[i].name;
        scanf("%d:%d:%d:%d",&month,&s[i].dd,&s[i].hh,&s[i].mm);
        s[i].len=s[i].dd*24*60+s[i].hh*60+s[i].mm;
        char op[10]; scanf("%s",op);
        if(op[1]=='n') s[i].f=1;
        else s[i].f=0;
    }
    memset(flag,0,sizeof flag);

    sort(s+1,s+1+n,cmp);
    int tot=0;
    for(int i=1;i<=n;i++)
    {
        if(flag[i]==1) continue;
        if(s[i].f==0) continue;
        for(int j=i+1;j<=n;j++)
        {

            if(s[i].name==s[j].name)
            {
                if(s[j].f==0&&flag[j]==0){
                    ans[++tot]=s[i];
                    ans[++tot]=s[j];
                    flag[i]=1; flag[j]=1;
                }
                break;
            }
        }
    }

    sort(ans+1,ans+1+tot,cmp2);

    int pos=1;
    cout<<ans[1].name<<" "; printf("%02d\n",month);
    printf("%02d:%02d:%02d ",ans[pos].dd,ans[pos].hh,ans[pos].mm);
    printf("%02d:%02d:%02d ",ans[pos+1].dd,ans[pos+1].hh,ans[pos+1].mm);
    printf("%d ",ans[pos+1].len-ans[pos].len);
    printf("$%.2lf\n",1.0*get(1,2)/100);

    double sum=1.0*get(1,2)/100;

    pos=pos+2;

    for(int i=pos;i<=tot;i=i+2)
    {
        if(ans[i].name==ans[i-2].name)
        {
            printf("%02d:%02d:%02d ",ans[i].dd,ans[i].hh,ans[i].mm);
            printf("%02d:%02d:%02d ",ans[i+1].dd,ans[i+1].hh,ans[i+1].mm);
            printf("%d ",ans[i+1].len-ans[i].len);
            printf("$%.2lf\n",1.0*get(i,i+1)/100);
            sum=sum+1.0*get(i,i+1)/100;
        }
        else
        {
            printf("Total amount: $%.2lf\n",sum);
            cout<<ans[i].name<<" "; printf("%02d\n",month);
            printf("%02d:%02d:%02d ",ans[i].dd,ans[i].hh,ans[i].mm);
            printf("%02d:%02d:%02d ",ans[i+1].dd,ans[i+1].hh,ans[i+1].mm);
            printf("%d ",ans[i+1].len-ans[i].len);
            printf("$%.2lf\n",1.0*get(i,i+1)/100);
            sum=1.0*get(i,i+1)/100;
        }
    }
    printf("Total amount: $%.2lf\n",sum);
    return 0;
}

 

转载于:https://www.cnblogs.com/zufezzt/p/5497638.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值