题目描述
Tehran municipality has set up a new charging method for the Congestion Charging Zone (CCZ) which controls the passage of vehicles in Tehran’s high-congestion areas in the congestion period (CP) from 6:30 to 19:00. There are plate detection cameras inside or at the entrances of the CCZ recording vehicles seen at the CCZ. The table below summarizes the new charging method.
Congestion Charging Zone 水题
Note that the first time and the last time that a vehicle is seen in the CP may be the same. Write a program to compute the amount of charge of a given vehicle in a specific day.

输入
The first line of the input contains a positive integer n (1 ⩽ n ⩽ 100) where n is the number of records for a vehicle. Each of the next n lines contains a time at which the vehicle is seen. Each time is of form :, where is an integer number between 0 and 23 (inclusive) and is formatted as an exactly two-digit number between 00 and 59 (inclusive).

输出
Print the charge to be paid by the owner of the vehicle in the output.

样例输入
4
7:30
2:20
7:30
17:30
样例输出
36000

主要麻烦在读题上,读懂题目就是一道水题,意思是说给了你一天内一辆车出现的情况,选取在6:30到19:00的部分,在这个部分里面选最早和最晚的时间,根据这个时间对照表求出要交的费用,如果一天内这辆车没出现过,那就不需要交钱直接输出0.

AC代码

#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
struct Time{
	int h;
	int m;
	int num;
};
struct Time t[105];
bool cmp(struct Time x,struct Time y)
{
	if(x.h==y.h) return x.m<y.m;
	else return x.h<y.h;
}
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%d:%d",&t[i].h,&t[i].m);
		t[i].num=t[i].h*100+t[i].m;
		if(t[i].num<630||t[i].num>1900) i--,n--;
	}
	sort(t,t+n,cmp);
	if(n==0)
		cout<<"0"<<endl;
	else if(t[0].num>=630&&t[0].num<=1000)
	{
		if(t[n-1].num>=630&&t[n-1].num<=1600)
			cout<<"24000"<<endl;
		else if(t[n-1].num>=1601&&t[n-1].num<=1900)
			cout<<"36000"<<endl;
	}
	else if(t[0].num>=1001&&t[0].num<=1600&&t[n-1].num>=1001&&t[n-1].num<=1600)
		cout<<"16800"<<endl;
	else if(t[0].num>=1001&&t[0].num<=1900&&t[n-1].num>=1601&&t[n-1].num<=1900)
		cout<<"24000"<<endl;
}

相关文章: