PAT 甲级 A1016 (2019/02/23)0/25

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1010;
int toll[25];
struct Record {
    char name[25];
    int month, dd, hh, mm;
    bool status;
} rec[maxn], temp;
bool cmp(Record a, Record b) {
    int s = strcmp(a.name, b.name);
    if(s != 0) return s < 0;
    else if(a.month != b.month) return a.month < b.month;
    else if(a.dd != b.dd) return a.dd < b.dd;
    else if(a.hh != b.hh) return a.hh < b.hh;
    else return a.mm < b.mm;
}
void get_ans(int on, int off, int& time, int& money) {
    temp = rec[on];
    while(temp.dd < rec[off].dd || temp.hh < rec[off].hh || temp.mm < rec[off].mm) {
        time++;
        money += toll[temp.hh];
        temp.mm++;
        if(temp.mm >= 60) {
            temp.mm = 0;
            temp.hh++;
        }
        if(temp.hh >= 24) {
            temp.hh = 0;
            temp.dd++;
        }
    }
}
int main() {
    for(int i = 0; i < 24; i++) {
        scanf("%d", &toll[i]);
    }
    int n;
    scanf("%d", &n);
    char line[10];
    for(int i = 0; i < n; i++) {
        scanf("%s", rec[i].name);
        scanf("%d:%d:%d:%d", &rec[i].month, &rec[i].dd, &rec[i].hh, &rec[i].mm);
        scanf("%s", line);
        if(strcmp(line, "on-line") == 0) {
            rec[i].status = true;
        } else {
            rec[i].status = false;
        }
    }
    sort(rec, rec + n, cmp);
    int on = 0, off, next;
    while(on < n) {
        int needPrint = 0;
        next = on;
        while(next < n && strcmp(rec[next].name, rec[on].name) == 0) {
            if(needPrint == 0 && rec[next].status == true) {
                needPrint = 1;
            } else if(needPrint == 1 && rec[next].status == false) {
                needPrint = 2;
            }
            next++;
        }
        if(needPrint < 2) {
            on = next;
            continue;
        }
        int AllMoney = 0;
        printf("%s %02d\n", rec[on].name, rec[on].month);
        while(on < next) {
            while(on < next - 1
                  && !(rec[on].status == true && rec[on + 1].status == false)) {
                on++;
            }
            off = on + 1;
            if(off == next) {
                on = next;
                break;
            }
            printf("%02d:%02d:%02d ", rec[on].dd, rec[on].hh, rec[on].mm);
            printf("%02d:%02d:%02d ", rec[off].dd, rec[off].hh, rec[off].mm);
            int time = 0, money = 0;
            get_ans(on, off, time, money);
            AllMoney += money;
            printf("%d $%.2f\n", time, money / 100.0);
            on = off + 1;
        }
        printf("Total amount: $%.2f\n", AllMoney / 100.0);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/zjsaipplp/p/10425254.html

时间: 2024-11-05 23:33:31

PAT 甲级 A1016 (2019/02/23)0/25的相关文章

PAT 甲级 A1054 (2019/02/23)

1 #include<cstdio> 2 #include<map> 3 using namespace std; 4 int main(){ 5 int m, n, element; 6 scanf("%d %d", &m, &n); // 行数与列数 7 map<int, int> Count; // 数字与出现次数的map映射 8 for(int i = 0; i < m; i++){ 9 for(int j = 0; j

PAT甲级【2019年3月考题】——A1158 TelefraudDetection【25】

Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting victims lose their entire life savings. To stop this crime, you are supposed to write a program to detect those suspects from a huge amount of phone c

PAT 甲级 1067 Sort with Swap(0, i) (25 分)(贪心,思维题)*

1067 Sort with Swap(0, i) (25 分) Given any permutation of the numbers {0, 1, 2,..., N−1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2, 1, 3} we may ap

PAT甲级——A1067 Sort with Swap(0, i)

Given any permutation of the numbers {0, 1, 2,..., N−1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2, 1, 3} we may apply the swap operations in the fo

【PAT甲级】1110 Complete Binary Tree (25分)

题意: 输入一个正整数N(<=20),代表结点个数(0~N-1),接着输入N行每行包括每个结点的左右子结点,'-'表示无该子结点,输出是否是一颗完全二叉树,是的话输出最后一个子结点否则输出根节点. trick: 用char输入子结点没有考虑两位数的结点??... stoi(x)可以将x转化为十进制整数 AAAAAccepted code: 1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace

PAT 甲级1002 A+B for Polynomials (25)

1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue This time, you are supposed to find A+B where A and B are two polynomials. Input Each input file contains one test case. Each case occupies 2 lines, an

开班前自学—python基础一 2019.02.23

一.学习期间要求 1.不允许迟到.(每次迟到罚20,扣5分) 2.不允许楼道内吸烟,不乱扔杂物. 3.尊重老师们.(老师包括主教/上课老师...) 4.听话 二.初识计算机 三 python的发展 Python 2x vs Python 3x 1.3x:源码规范,'优雅','明确','简单'.2x相反,2020. 2.3x:默认utf-8编码:2x:默认ascii编码.sacii码无法显示中文. 2x修改默认编码: # -*- encoding : utf-8 -*- 四 编译语言的分类 1.

PAT 甲级 1066 Root of AVL Tree (25 分)(快速掌握平衡二叉树的旋转,内含代码和注解)***

1066 Root of AVL Tree (25 分) An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this

【PAT甲级】1052 Linked List Sorting (25分)

1052 Linked List Sorting (25分) A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list, yo