题目描述
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.
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 <hour>:<minute>, where <hour> is an integer number between 0 and 23 (inclusive) and <minute> 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:30通过,并根据检测照相机拍下的照片进行收费
输入n个时间根据时间输出需要交纳的费用。
题解:
题目表达的意思很模糊,比赛的时候看了很久都没想出来T T,需要注意:
1.输入的所有时间都是一天中的
2.还有第一次看到的时间和最后一次看到的时候是表给的情况才根据表进行收费。
3.输出的时间只是看到的时候,并不是按先后顺序排列的。
如果这些都搞明白那么这道题也就没问题了。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
const int maxn = 100+2;
int a[maxn];
using namespace std;
int ope(int first,int last){
if(630<=first&&first<=1000&&630<=last&&last<=1600)
return 24000;
else if(630<=first&&first<=1000&&1601<=last&&last<=1900)
return 36000;
else if(1001<=first&&first<=1600&&1001<=last&&last<=1600)
return 16800;
else if(1001<=first&&first<=1900&&1601<=last&&last<=1900)
return 24000;
}
int main()
{
int t;
int l = 0;
int num = 0;
int n;
int first,last;
first = 0;
last = 0;
cin>>t;
int flag = 0;
for(int z = 0;z<t;z++){
int n = 0;
string s;
cin>>s;
int len = s.length();
for(int i = 0;i < len;i++){
if(s[i]!=':'){
n = n*10+s[i]-'0';
if(630<=n&&1900>=n){
a[l++] = n;
}
}
}
}
sort(a,a+l);
if(l<1){
cout<<0<<endl;
}
else{
int result = ope(a[0],a[l-1]);
cout<<result<<endl;
}
return 0;
}