15分的代码
#include<bits/stdc++.h>
using namespace std;
struct Node{
string name;
int month;
int time;
int flag;
};
int ansday=0;
vector<int> rate;
bool cmp(Node a,Node b){
if(a.name!=b.name) return a.name<b.name;
else return a.time<b.time;
}
double getmoney(int start,int end){
int day1=start/(24*60);
int hour1=start%(24*60)/60;
int minute1=start%(24*60)%60;
int day2=end/(24*60);
int hour2=end%(24*60)/60;
int minute2=end%(24*60)%60;
double ans=0;
if(day1==day2){
for(int i=hour1;i<=hour2;i++){
if(i==hour1){
ans+=rate[i]*(60-minute1);
}else if(i!=hour2){
ans+=rate[i]*60;
}else if(i==hour2){
ans+=rate[i]*minute2;
}
}
return ans/(100*1.0);
}else{
if(end-start>(24*60)){
ans+=(end-start)/(24*60)*ansday;
for(int i=hour1;i<=hour2;i++){
if(i==hour1){
ans+=rate[i]*(60-minute1);
}else if(i!=hour2){
ans+=rate[i]*60;
}else if(i==hour2){
ans+=rate[i]*minute2;
}
}
return ans/(100*1.0);
}else if(end-start==(24*60)){
ans+=(end-start)/(24*60)*ansday;
return ans/(100*1.0);
}else if(end-start<(24*60)){
for(int i=hour2;i<=hour1;i++){
if(i==hour2){
ans+=rate[i]*(60-minute2);
}else if(i!=hour1){
ans+=rate[i]*60;
}else if(i==hour1){
ans+=rate[i]*minute1;
}
}
return ans/(100*1.0);
}
}
}
int main()
{
freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);
rate.resize(24);
for(int i=0;i<24;i++){
cin>>rate[i];
ansday+=rate[i]*60;
}
int n;cin>>n;vector<Node> ppp;ppp.resize(n);
for(int i=0;i<n;i++){
cin>>ppp[i].name;
int month1,day1,hour1,minute1;
scanf("%d:%d:%d:%d",&month1,&day1,&hour1,&minute1);
ppp[i].month=month1;
ppp[i].time=day1*24*60+hour1*60+minute1;
string status;
cin>>status;
if(status=="on-line"){
ppp[i].flag=1;
}else{
ppp[i].flag=0;
}
}
sort(ppp.begin(),ppp.end(),cmp);
vector<Node> temp;
for(int i=1;i<ppp.size();i++){
if(ppp[i].name==ppp[i-1].name&&(ppp[i-1].flag==1&&ppp[i].flag==0)){
temp.push_back(ppp[i-1]);
temp.push_back(ppp[i]);
}
}
map<string,int> sign;
map<string,double> hash;int sign1=0;
for(int i=0;i<temp.size();i+=2){
if(sign[temp[i].name]==0){
cout<<temp[i].name;printf(" %02d\n",temp[i].month);
sign[temp[i].name]=1;
}
printf("%02d:%02d:%02d %02d:%02d:%02d ",temp[i].time/(24*60),temp[i].time%(24*60)/60,temp[i].time%(24*60)%60,temp[i+1].time/(24*60),temp[i+1].time%(24*60)/60,temp[i+1].time%(24*60)%60);
printf("%d $%.2lf\n",temp[i+1].time-temp[i].time,getmoney(temp[i].time,temp[i+1].time));
hash[temp[i].name]+=getmoney(temp[i].time,temp[i+1].time);
if(i+2<temp.size()&&hash[temp[i+2].name]==0){
printf("Total amount: $%.2lf\n",hash[temp[i].name]);sign1=1;
}
if(i==temp.size()-2&&sign1==1){
printf("Total amount: $%.2lf\n",getmoney(temp[i].time,temp[i+1].time));
}
}
return 0;
}
22分的代码
#include<bits/stdc++.h>
using namespace std;
struct Node{
string name;
int month;
int time;
int flag;
};
int ansday=0;
vector<int> rate;
bool cmp(Node a,Node b){
if(a.name!=b.name) return a.name<b.name;
else return a.time<b.time;
}
double getmoney(int start,int end){
int day1=start/(24*60);
int hour1=start%(24*60)/60;
int minute1=start%(24*60)%60;
int day2=end/(24*60);
int hour2=end%(24*60)/60;
int minute2=end%(24*60)%60;
double ans=0,ans1=0,ans2=0;
ans1+=rate[hour1]*minute1+ansday*day1;
ans2+=rate[hour2]*minute2+ansday*day2;
for(int i=0;i<hour1;i++){
ans1+=rate[i]*60;
}
for(int i=0;i<hour2;i++){
ans2+=rate[i]*60;
}
return (ans2-ans1)/100.0;
}
int main()
{
freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);
rate.resize(24);
for(int i=0;i<24;i++){
cin>>rate[i];
ansday+=rate[i]*60;
}
int n;cin>>n;vector<Node> ppp;ppp.resize(n);
for(int i=0;i<n;i++){
cin>>ppp[i].name;
int month1,day1,hour1,minute1;
scanf("%d:%d:%d:%d",&month1,&day1,&hour1,&minute1);
ppp[i].month=month1;
ppp[i].time=day1*24*60+hour1*60+minute1;
string status;
cin>>status;
if(status=="on-line"){
ppp[i].flag=1;
}else{
ppp[i].flag=0;
}
}
sort(ppp.begin(),ppp.end(),cmp);
vector<Node> temp;
for(int i=1;i<ppp.size();i++){
if(ppp[i].name==ppp[i-1].name&&(ppp[i-1].flag==1&&ppp[i].flag==0)){
temp.push_back(ppp[i-1]);
temp.push_back(ppp[i]);
}
}
map<string,int> sign;
map<string,double> hash;int sign1=0;
for(int i=0;i<temp.size();i+=2){
if(sign[temp[i].name]==0){
cout<<temp[i].name;printf(" %02d\n",temp[i].month);
sign[temp[i].name]=1;
}
printf("%02d:%02d:%02d %02d:%02d:%02d ",temp[i].time/(24*60),temp[i].time%(24*60)/60,temp[i].time%(24*60)%60,temp[i+1].time/(24*60),temp[i+1].time%(24*60)/60,temp[i+1].time%(24*60)%60);
printf("%d $%.2lf\n",temp[i+1].time-temp[i].time,getmoney(temp[i].time,temp[i+1].time));
hash[temp[i].name]+=getmoney(temp[i].time,temp[i+1].time);
if(i+2<temp.size()&&hash[temp[i+2].name]==0){
printf("Total amount: $%.2lf\n",hash[temp[i].name]);sign1=1;
}
if(i==temp.size()-2&&sign1==1){
printf("Total amount: $%.2lf\n",getmoney(temp[i].time,temp[i+1].time));
}
}
return 0;
}
AC代码
#include<bits/stdc++.h>
using namespace std;
struct Node{
string name;
int month;
int time;
int flag;
};
int ansday=0;
vector<int> rate;
bool cmp(Node a,Node b){
if(a.name!=b.name) return a.name<b.name;
else return a.time<b.time;
}
double getmoney(int start,int end){
int day1=start/(24*60);
int hour1=start%(24*60)/60;
int minute1=start%(24*60)%60;
int day2=end/(24*60);
int hour2=end%(24*60)/60;
int minute2=end%(24*60)%60;
double ans=0,ans1=0,ans2=0;
ans1+=rate[hour1]*minute1+ansday*day1;
ans2+=rate[hour2]*minute2+ansday*day2;
for(int i=0;i<hour1;i++){
ans1+=rate[i]*60;
}
for(int i=0;i<hour2;i++){
ans2+=rate[i]*60;
}
return (ans2-ans1)/100.0;
}
int main()
{
freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);
rate.resize(24);
for(int i=0;i<24;i++){
cin>>rate[i];
ansday+=rate[i]*60;
}
int n;cin>>n;vector<Node> ppp;ppp.resize(n);
for(int i=0;i<n;i++){
cin>>ppp[i].name;
int month1,day1,hour1,minute1;
scanf("%d:%d:%d:%d",&month1,&day1,&hour1,&minute1);
ppp[i].month=month1;
ppp[i].time=day1*24*60+hour1*60+minute1;
string status;
cin>>status;
if(status=="on-line"){
ppp[i].flag=1;
}else{
ppp[i].flag=0;
}
}
sort(ppp.begin(),ppp.end(),cmp);
vector<Node> temp;map<string,vector<Node> > mp;
for(int i=1;i<ppp.size();i++){
if(ppp[i].name==ppp[i-1].name&&(ppp[i-1].flag==1&&ppp[i].flag==0)){
temp.push_back(ppp[i-1]);
temp.push_back(ppp[i]);
mp[ppp[i].name].push_back(ppp[i-1]);
mp[ppp[i].name].push_back(ppp[i]);
}
}
for(auto it:mp){
double tttt=0;
cout<<it.first<<' ';
vector<Node> temp=it.second;
printf("%02d\n",temp[0].month);
for(int i=0;i<temp.size();i+=2){
printf("%02d:%02d:%02d %02d:%02d:%02d ",temp[i].time/(24*60),temp[i].time%(24*60)/60,temp[i].time%(24*60)%60,temp[i+1].time/(24*60),temp[i+1].time%(24*60)/60,temp[i+1].time%(24*60)%60);
printf("%d $%.2lf\n",temp[i+1].time-temp[i].time,getmoney(temp[i].time,temp[i+1].time));
tttt+=getmoney(temp[i].time,temp[i+1].time);
}
printf("Total amount: $%.2lf\n",tttt);
}
/*map<string,int> sign;
map<string,double> hash;int sign1=0;
for(int i=0;i<temp.size();i+=2){
if(sign[temp[i].name]==0){
cout<<temp[i].name;printf(" %02d\n",temp[i].month);
sign[temp[i].name]=1;
}
printf("%02d:%02d:%02d %02d:%02d:%02d ",temp[i].time/(24*60),temp[i].time%(24*60)/60,temp[i].time%(24*60)%60,temp[i+1].time/(24*60),temp[i+1].time%(24*60)/60,temp[i+1].time%(24*60)%60);
printf("%d $%.2lf\n",temp[i+1].time-temp[i].time,getmoney(temp[i].time,temp[i+1].time));
hash[temp[i].name]+=getmoney(temp[i].time,temp[i+1].time);
if(i+2<temp.size()&&hash[temp[i+2].name]==0){
printf("Total amount: $%.2lf\n",hash[temp[i].name]);sign1=1;
}
if(i==temp.size()-2&&sign1==1){
printf("Total amount: $%.2lf\n",getmoney(temp[i].time,temp[i+1].time));
}
}*/
return 0;
}
参考柳神的代码(我与大佬差的不是一点,是两点~)