1016. Phone Bills (25)

有些用户没有合法账单,不输出。另外程序红字部分需要注意

#define  _CRT_SECURE_NO_WARNINGS

#include<cstdio>  
#include<cstring>  
#include<cmath>  
#include<string>  
#include<vector>  
#include<map>  
#include<iostream>  
#include<queue>  
#include<algorithm>  


using namespace std;


int rate[24] = {0};


struct Record
{
char name[21];
int month, day, hour, minute;
bool on_line;
Record()
{
month = 0; day = 0; hour = 0; minute=0;
on_line = true;
name[0] = '\0';
}
};
struct Time
{
int month, day, hour, minute;
Time operator=(Record r)
{
month = r.month;
day = r.day; 
hour = r.hour;
minute = r.minute; 
return *this;
}
};
bool cmp(Record r1, Record r2)
{
if (strcmp(r1.name, r2.name)!=0)
return strcmp(r1.name, r2.name) < 0;
else if (r1.day != r2.day)
return r1.day < r2.day;
else if (r1.hour != r2.hour)
return r1.hour < r2.hour;
else 
return r1.minute < r2.minute; 
}
float count(Time t,Record r,int &tim)
{
float a=0;
int m1, m2;
m1 = (t.day * 24 + t.hour) * 60 + t.minute;
m2 = (r.day * 24 + r.hour) * 60 + r.minute;
tim = m2 - m1;
while (m1 < m2)
{
int tmp = (m1 / 60 + 1) * 60;
if (m2 >= tmp)
{
a += (tmp - m1)*rate[(m1/60)%24];
m1 = tmp;
}
else
{
a += (m2 - m1)*rate[(m1 / 60) % 24];
m1 = m2;
}
}
return a/100.0;
}
int main()

for (int i = 0; i < 24; i++)
{
cin >> rate[i];
}
int N;
cin >> N;
Record *rec = new Record[N];
for (int i = 0; i < N; i++)
{
char tmp[10] = {0};
scanf("%s %d:%d:%d:%d %s", rec[i].name, &rec[i].month, &rec[i].day, &rec[i].hour, &rec[i].minute, tmp);
if (strcmp(tmp, "off-line") == 0)
rec[i].on_line = false;
}
sort(rec,rec+N,cmp);


char name[21] = {0};
strcpy(name,rec[0].name);
int month = rec[0].month;
bool online = rec[0].on_line;
Time t;
t = rec[0];
float total = 0;
bool bOut = true; 
/*CYJJ 01
01:05:59 01:07:00 61 $12.10
Total amount: $12.10*/
for (int i = 1; i < N; i++)
{
if (strcmp(rec[i].name, name) == 0)
{
if (online&&!rec[i].on_line)
{
//计算当前时间-t的花费;
int tim = 0;
float f = count(t, rec[i], tim);
if (tim > 0)
{
if (bOut)
{
bOut = false;
printf("%s %02d\n", name, month);
}
//输出
printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n",
t.day, t.hour, t.minute, rec[i].day, rec[i].hour, rec[i].minute, tim, f);
total += f;//total+=当前花费

}
online = rec[i].on_line;
       t = rec[i];

}
else
{
if (total>0)
printf("Total amount: $%.2f\n",total);
 
total = 0;
strcpy(name, rec[i].name);
online = rec[i].on_line;
t = rec[i];
bOut = true; //printf("%s %02d\n", name, month);
}
}
if (total>0)
printf("Total amount: $%.2f\n", total);
 
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值