Source:

Description:

Input Specification:

Output Specification:

Sample Input:

Sample Output:

Keys:

  • 模拟题

Code:

 /*
Data: 2019-07-17 19:24:07
Problem: PAT_A1016#Phone Bills
AC: 53:32 题目大意:
统计月度话费账单
输入:
第一行给出,各小时的话费权重cent/minute
第二行给出,通话数N<=1e3
接下来N行,name,time,status(on/off)
输出:
打印各个用户的账单,姓名递增
name,month
start,end,time,costs
total amount
*/ #include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1e3+,H=;
struct node
{
string name,status;
string time;
}info[M];
struct mode
{
int dd,hh,mm;
};
int n,w[H]; bool cmp(const node &a, const node &b)
{
if(a.name != b.name)
return a.name < b.name;
else
return a.time < b.time;
} mode Time(string s)
{
mode t;
t.dd = atoi(s.substr(,).c_str());
t.hh = atoi(s.substr(,).c_str());
t.mm = atoi(s.substr(,).c_str());
return t;
} int Pay(string s1, string s2, int &time, int &cost)
{
mode t1 = Time(s1);
mode t2 = Time(s2);
while(t1.dd!=t2.dd || t1.hh!=t2.hh || t1.mm!=t2.mm)
{
time++;
cost += w[t1.hh];
t1.mm++;
if(t1.mm==)
{
t1.mm=;
t1.hh++;
}
if(t1.hh==)
{
t1.hh=;
t1.dd++;
}
}
return cost;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif for(int i=; i<H; i++)
scanf("%d", &w[i]);
scanf("%d", &n);
for(int i=; i<n; i++)
cin >> info[i].name >> info[i].time >> info[i].status;
sort(info,info+n,cmp);
for(int i=; i<n; i++)
{
int valid=,bill=;
while(i<n && info[i-].name==info[i].name)
{
int cost=,time=;
if(info[i-].status=="on-line"&&info[i].status=="off-line")
{
if(!valid) cout << info[i].name << " " << info[].time.substr(,) << endl;
valid=;
bill += Pay(info[i-].time,info[i].time,time,cost);
cout << info[i-].time.substr() << " " << info[i].time.substr();
printf(" %d $%.2f\n", time,1.0*cost/100.0);
}
i++;
}
if(valid) printf("Total amount: $%.2f\n", 1.0*bill/100.0);
} return ;
}
05-28 08:18
查看更多