我是靠谱客的博主 虚拟烧鹅,最近开发中收集的这篇文章主要介绍PAT A1016求测试点例子,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
struct customer {
char name[21];
char on_off[10];
int tagon;//1为on 0为off
int month;
int day;
int hour;
int minute;
bool tag;
}cus[1005];
int cost[24];
bool cmp1(struct customer a, struct customer b) {//按姓名排序从小到大
return strcmp(a.name, b.name) < 0;
}
bool cmp(struct customer a,struct customer b) {
if (a.day == b.day) {
if (a.hour == b.hour) {
return a.minute < b.minute;
}
else {
return a.hour < b.hour;
}
}
else {
return a.day < b.day;
}
}
double charge(int fday,int fhour, int fmin, int eday,int ehour, int emin,int &total) {//计算费用
int i,j;
double cos = 0.0;
if (fday != eday) {//不在同一天
while (fday != eday || fhour != ehour || fmin != emin) {
cos += 1.0 *cost[fhour] / 100;
fmin++;total++;
if (fmin == 60) {
fmin = 0;fhour++;
}
if (fhour == 24) {
fhour = 0;
fday++;
}
}
}
else {
if (fday == eday && fhour != ehour) {//同一天
if (ehour - fhour == 1) {//相差不超过两个小时
total = total + (60 - fmin);
cos = cos + 1.0 * (60 - fmin) * cost[fhour] / 100;
total += emin;
cos = cos + 1.0 * emin * cost[ehour] / 100;
}
else {//相差两个小时以上
total += (60 - fmin);
total += emin;
cos = cos + 1.0 * (60 - fmin) * cost[fhour] / 100;
cos = cos + 1.0 * emin * cost[ehour] / 100;
i = fhour + 1;
j = ehour - 1;
for (int k = i;k <= j;k++) {
total += 60;
cos += 1.0 * 60 * cost[k] / 100;
}
}
}
else {
cos = 1.0 * (emin - fmin) * cost[fhour] / 100;
total = emin - fmin;
}
}
return cos;
}
void process(vector<customer>cus) {//处理每个人的信息
double sum = 0.0,cos=0.0;
int total=0;
int d1, h1, m1, d2, h2,m2,count=0;
if (cus.size() != 0) {
sort(cus.begin(), cus.end(), cmp);
while (cus.size()!=0&&cus[0].on_off == 0) {//开头是off状态,无效,删去
cus.erase(cus.begin());
}
if (cus.size() == 0) {
return;
}
while (!cus.empty()) {
total = 0;
d1 = cus[0].day;h1 = cus[0].hour;m1 = cus[0].minute;cus.erase(cus.begin());//第一个是on
if (cus.empty()) {//判断vector是否已经空了
if (sum != 0) {
printf("Total amount: $%.2lfn", sum);
}
return;
}
while (!cus.empty() &&cus[0].tagon == 1) {//如果下一个还是on,则上一个on无效
d1 = cus[0].day;h1 = cus[0].hour;m1 = cus[0].minute;cus.erase(cus.begin());//第一个是on
}
if (cus.empty()) {//判断vector是否已经空了
if (sum != 0) {
printf("Total amount: $%.2lfn", sum);
}
return;
}
d2 = cus[0].day;h2 = cus[0].hour;m2 = cus[0].minute;cus.erase(cus.begin());//找到对应的off
cos=charge(d1, h1, m1, d2, h2, m2, total);
count++;
if (count == 1) {
printf("%s %02dn", cus[0].name, cus[0].month);
}
printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2lfn", d1, h1, m1, d2, h2, m2, total, cos);
sum = sum + cos;
while (!cus.empty() && cus[0].on_off == 0) {//开头是off状态,无效,删去
cus.erase(cus.begin());
}
if (cus.empty()) {
if (sum != 0) {
printf("Total amount: $%.2lfn", sum);
}
return;
}
}
}
else {
return;
}
}
int main() {
double cos = 0.0;
int day1, hour1, minute1,day2,hour2,minute2,total=0;
int i, j, n;
for (i = 0;i < 24;i++) {
scanf("%d", &cost[i]);
}
scanf("%d", &n);
for (i = 0;i < n;i++) {
scanf("%s%d:%d:%d:%d%s", cus[i].name, &cus[i].month, &cus[i].day, &cus[i].hour, &cus[i].minute, cus[i].on_off);
if (strcmp(cus[i].on_off, "on-line") == 0) {
cus[i].tagon = 1;
}
else {
cus[i].tagon = 0;
}
}
sort(cus, cus + n, cmp1);//先按姓名排序
int pair = 0, len, index = 0;
char name1[21];
len = 0;
vector<struct customer>vec;
vec.push_back(cus[0]);
strcpy(name1, vec[0].name);
while (index < n) {
index++;
if (strcmp(name1, cus[index].name) == 0) {
vec.push_back(cus[index]);
}
else {
process(vec);
vec.clear();//
strcpy(name1, cus[index].name);
vec.push_back(cus[index]);//新结点重新入队
}
}
return 0;
}## PAT A1016 测试点123错了 不解原因,求例子!

最后

以上就是虚拟烧鹅为你收集整理的PAT A1016求测试点例子的全部内容,希望文章能够帮你解决PAT A1016求测试点例子所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(35)

评论列表共有 0 条评论

立即
投稿
返回
顶部