PAT甲级 1016

Phone Bills

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 long-distance call, the time will be recorded, and so will be the time when the customer hangs up the phone. Every calendar month, a bill is sent to the customer for each minute called (at a rate determined by the time of day). Your job is to prepare the bills for each month, given a set of phone call records.

Input Specification:

Each input file contains one test case. Each case has two parts: the rate structure, and the phone call records.

The rate structure consists of a line with 24 non-negative integers denoting the toll (cents/minute) from 00:00 - 01:00, the toll from 01:00 - 02:00, and so on for each hour in the day.

The next line contains a positive number N (<= 1000), followed by N lines of records. Each phone call record consists of the name of the customer (string of up to 20 characters without space), the time and date (mm:dd:hh:mm), and the word “on-line” or “off-line”.

For each test case, all dates will be within a single month. Each “on-line” record is paired with the chronologically next record for the same customer provided it is an “off-line” record. Any “on-line” records that are not paired with an “off-line” record are ignored, as are “off-line” records not paired with an “on-line” record. It is guaranteed that at least one call is well paired in the input. You may assume that no two records for the same customer have the same time. Times are recorded using a 24-hour clock.

Output Specification:

For each test case, you must print a phone bill for each customer.

Bills must be printed in alphabetical order of customers’ names. For each customer, first print in a line the name of the customer and the month of the bill in the format shown by the sample. Then for each time period of a call, print in one line the beginning and ending time and date (dd:hh:mm), the lasting time (in minute) and the charge of the call. The calls must be listed in chronological order. Finally, print the total charge for the month in the format shown by the sample.

Sample Input:
10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10
10
CYLL 01:01:06:01 on-line
CYLL 01:28:16:05 off-line
CYJJ 01:01:07:00 off-line
CYLL 01:01:08:03 off-line
CYJJ 01:01:05:59 on-line
aaa 01:01:01:03 on-line
aaa 01:02:00:01 on-line
CYLL 01:28:15:41 on-line
aaa 01:05:02:24 on-line
aaa 01:04:23:59 off-line

Sample Output:
CYJJ 01
01:05:59 01:07:00 61 12.10Totalamount: 12.10
CYLL 01
01:06:01 01:08:03 122 24.4028:15:4128:16:0524 3.85
Total amount: 28.25aaa0102:00:0104:23:594318 638.80
Total amount: $638.80


模拟题

#include <string.h>
#include <stdio.h>
#include <map>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

const int maxsize=1000+10;
struct node{
  int month,time;
  bool status;
  node(int m,int d,int h,int mi,bool s):
  month(m),time(d*24*60+h*60+mi),status(s){}
};
vector<node> vn[maxsize];
map<string,int> ms;   //#include<string>
int price[24];

bool getStatus(char status[]){
  if(status[1]=='n')return true;
  return false;
}
bool cmp(node a,node b){
  return a.time<b.time;
}
int main(){
  //freopen("./in","r",stdin);
  char name[20+1];
  int i;
  int n;
  for(i=0;i<24;i++)scanf("%d",price+i);
  scanf("%d",&n);
  string str;
  map<string,int>::iterator mit;
  int cur,pos=0;
  int month,day,hour,minute;
  char status[20];
  for(i=0;i<n;i++){
    scanf("%s",name);
    str=string(name);
    mit=ms.find(str);
    if(mit!=ms.end()){
      cur=(*mit).second;
    }else{
      cur=pos;
      pos++;
      ms.insert(make_pair(str,cur));
    }
    scanf("%d:%d:%d:%d %s",&month,&day,&hour,&minute,status);
    node a(month,day,hour,minute,getStatus(status));
    vn[cur].push_back(a);
  }

  bool flag,bflag;
  int ftime,stime;
  double toll,total_toll;
  vector<node>::iterator it;
  for(mit=ms.begin();mit!=ms.end();mit++){
    pos=(*mit).second;
    sort(vn[pos].begin(),vn[pos].end(),cmp);
    bflag=false;
    it=vn[pos].begin();
    flag=true;
    for(;it!=vn[pos].end();it++){
      if(flag && (*it).status){
        flag=false;
        continue;
      }
      if(!flag && !(*it).status){
        bflag=true;
        flag=true;
        break;
      }
    }
    if(!bflag)continue;

    strcpy(name,(*mit).first.c_str());
    printf("%s",name);

    it=vn[pos].begin();
    printf(" %02d\n",(*it).month);
    total_toll=0;

    for(;it!=vn[pos].end();it++){
      if(!flag && (*it).status){
        ftime=(*it).time;
        continue;
      }
      if(flag && (*it).status){
        ftime=(*it).time;
        flag=false;
        continue;
      }
      if(!flag && !(*it).status){
        stime=(*it).time;
        printf("%02d:%02d:%02d ",ftime/(24*60),ftime%(24*60)/60,ftime%60);
        printf("%02d:%02d:%02d %d ",stime/(24*60),stime%(24*60)/60,stime%60,stime-ftime);
        toll=0;
        if(ftime/60!=stime/60){
          toll+=(double(ftime/60*60+60-ftime))*price[ftime/60%24]/100;
          ftime=ftime/60*60+60;      
        }
        while(ftime+60<stime){
          toll+=60.0*price[ftime/60%24]/100;
          ftime+=60;
        }
        toll+=(double(stime-ftime))*price[ftime/60%24]/100;
        total_toll+=toll;
        printf("$%.2lf\n",toll);
        flag=true;
      }
    }
    printf("Total amount: $%.2lf\n",total_toll);
  }
  return 0;
}
### 关于 PAT 甲级 1024 题目 PAT (Programming Ability Test) 是一项编程能力测试,其中甲级考试面向有一定编程基础的学生。对于 PAT 甲级 1024 题目,虽然具体题目描述未直接给出,但从相似类型的题目分析来看,这类题目通常涉及较为复杂的算法设计。 #### 数据结构的选择与实现 针对此类问题,常用的数据结构包括但不限于二叉树节点定义: ```cpp struct Node { int val; Node* lchild, *rchild; }; ``` 此数据结构用于表示二叉树中的节点[^1]。通过这种方式构建的二叉树能够支持多种遍历操作,如前序、中序后序遍历等。 #### 算法思路 当处理涉及到图论的问题时,深度优先搜索(DFS)是一种常见的解题策略。特别是当需要寻找最优路径或访问尽可能多的节点时,结合贪心算法可以在某些情况下提供有效的解决方案[^2]。 #### 输入输出格式说明 根据以往的经验,在解决 PAT 类型的问题时,输入部分往往遵循特定模式。例如,给定 N 行输入来描述每个节点的信息,每行按照如下格式:“Address Data Next”,这有助于理解如何解析输入并建立相应的数据模型[^4]。 #### 数学运算示例 有时也会遇到基本算术表达式的求值问题,比如分数之间的加减乘除运算。下面是一些简单的例子展示不同情况下的计算结果: - \( \frac{2}{3} + (-2) = -\frac{7}{3}\) -2) = -\frac{4}{3}\) - \( \frac{2}{3} ÷ (-2) = -\frac{1}{3}\) 这些运算是基于样例提供的信息得出的结果[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值