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;
}
时间: 2024-10-09 02:50:58

PAT (Advanced Level) 1016. Phone Bills (25)的相关文章

PAT (Advanced Level) 1016 Phone Bills

题解 模拟.注意美元和美分的转换.如果一个人没有完整的消费记录什么都别输出 (呕~~) :). 代码 #include<bits/stdc++.h> using namespace std; struct node { string time,flag,other_time; int cost_sec,cost_money; node(string b,string c) {time=b;flag=c;} }; struct info { string name,time,flag; info

Pat(Advanced Level)Practice--1016(Phone Bills)

Pat1016代码 题目描述: A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a lon

PAT (Advanced Level) 1083. List Grades (25)

简单排序. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<iostream> #include<algorithm> using namespace std

PAT (Advanced Level) 1021. Deepest Root (25)

先并查集判断连通性,然后暴力每个点作为根节点判即可. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<queue> #include<vector> using namespace std; struct Edge { int a,b; }e[20000]; int n,sz

PAT (Advanced Level) 1020. Tree Traversals (25)

递归建树,然后BFS一下 #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<queue> #include<vector> using namespace std; const int maxn=40; int a[maxn],b[maxn]; int n,tot; struc

PAT (Advanced Level) 1114. Family Property (25)

简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; struct X { int id; int Father,Mother; int k;

PAT (Advanced Level) 1085. Perfect Sequence (25)

可以用双指针(尺取法),也可以枚举起点,二分终点. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; int n; long long k; long l

PAT (Advanced Level) 1071. Speech Patterns (25)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<iostream> #include<algorithm> using namespace std;

PAT (Advanced Level) 1109. Group Photo (25)

简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<string> #include<algorithm> #include<iostream> using namespace std