目录
1.Phone Bills
从构思到写完,总共约3小时,我太弱鸡了,淦
#include <cstdio>
#include <cctype>
#include <cstring>
#include <math.h>
#include <algorithm>
using namespace std;
struct record{
char name[22];
int date[4];
char status[10];
int flag = -1;
int status_temp=0;
int use = -1;
double sum=0;
int min=0;
}rec[1002];
bool cmp(record a,record b){
if(strcmp(a.name,b.name)!=0){
return strcmp(a.name,b.name)<0;
}else if(a.date[1]!=b.date[1]){
return a.date[1]<b.date[1];
}else if(a.date[2]!=b.date[2]){
return a.date[2]<b.date[2];
}else if(a.date[3]!=b.date[3]){
return a.date[3]<b.date[3];
}
}
int main(){
int cha[26];
for(int i=0;i<24;i++){
scanf("%d",&cha[i]);
}
int num;
scanf("%d",&num);
for(int i=0;i<num;i++){
scanf("%s %d:%d:%d:%d %s",&rec[i].name,&rec[i].date[0],&rec[i].date[1],&rec[i].date[2],&rec[i].date[3],&rec[i].status);
if(rec[i].status[1]=='n'){
rec[i].status_temp=1;
}else{
rec[i].status_temp=-1;
}
}
sort(rec,rec+num,cmp);
for(int i=0;i<num;i++){
if(rec[i].flag==-1){
for(int j=i+1;j<num;j++){
if(rec[j].flag==-1){
if(rec[i].status_temp==rec[j].status_temp){
break;
}
if((strcmp(rec[i].name,rec[j].name)==0)&&(rec[i].status_temp!=rec[j].status_temp)){
rec[i].flag = j;
rec[j].flag = i;
break;
}
}
}
}
}
int cou[1002]={0};
int n=0,pos=0;
int xx[1000]={0},l=1;
for(int i=0;i<num;i++){
if((rec[i].use==-1)&&(rec[i].flag!=-1)){
if(strcmp(rec[i].name,rec[n].name)!=0){
xx[l] = i;
l+=1;
n=i;
pos++;
cou[pos]+=1;
}else{
cou[pos]+=1;
}
rec[i].use=1;
rec[rec[i].flag].use=2;
int d1=rec[i].date[1],h1=rec[i].date[2],m1=rec[i].date[3];
int d2=rec[rec[i].flag].date[1],h2=rec[rec[i].flag].date[2],m2=rec[rec[i].flag].date[3];
int time[25]={0};
while(d1!=d2||h1!=h2||m1!=m2){
m1++;
time[h1]+=1;
if(m1==60){
h1+=1;
m1=0;
}
if(h1==24){
h1=0;
d1+=1;
}
}
for(int j=0;j<24;j++){
rec[i].min+=time[j];
rec[i].sum+=time[j]*cha[j];
}
rec[i].sum/=100;
}
}
for(int i=0;i<pos+1;i++){
double whole_sum = 0;
int n = 0;
printf("%s %02d\n",rec[xx[i]].name,rec[xx[i]].date[0]);
for(int j = xx[i];j<num;j++){
if(rec[j].use==1){
n++;
printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n",rec[j].date[1],rec[j].date[2],rec[j].date[3],rec[rec[j].flag].date[1],rec[rec[j].flag].date[2],rec[rec[j].flag].date[3],rec[j].min,rec[j].sum);
whole_sum+=rec[j].sum;
}
if(n==cou[i]){
break;
}
}
printf("Total amount: $%.2f\n",whole_sum);
}
return 0;
}