1016 Phone Bills

博客提及了15分的代码、22分的代码以及AC代码,还提到参考了柳神的代码,体现出与大佬代码水平的差距。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}

参考柳神的代码(我与大佬差的不是一点,是两点~)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值