1120 公交换乘

#include<iostream>
#include<list>
using namespace std;
 
typedef struct TrafficNumber
{
	int price;
	int startTime;
	TrafficNumber(int price, int startTime):price(price),startTime(startTime){}
 } TrafficNumber;
int main()
{
	int count;
	list<TrafficNumber> coupon;
	cin>>count;
	//总的花费 
	int totalCost = 0;
	while(count--)
	{
		int type;
		int price;
		int startTime;
		cin>>type>>price>>startTime;
		//坐地铁必须要付钱 
		if (type == 0)
		{
			totalCost += price;
			coupon.push_back(TrafficNumber(price, startTime));
			
		} 
		else
		{
			bool findCoupon = false;
			list<TrafficNumber>::iterator pCoupon;
			for(pCoupon = coupon.begin(); pCoupon!= coupon.end();)
			{
				TrafficNumber trafficNumber = *pCoupon;
				if(trafficNumber.startTime + 45 < startTime) 
				{
					// 已经超时的直接剔除 
					pCoupon=coupon.erase(pCoupon);
					continue;
				} 
				if (trafficNumber.price>=price)
				{
					// 消费过的优惠券剔除 
					findCoupon = true;
					pCoupon=coupon.erase(pCoupon);
					break;
				}
				pCoupon++; 
			}
			if (!findCoupon)
			{
				totalCost += price;
			}
		}
	} 
	cout<<totalCost<<endl; 
	return 0;
}
  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值