问题 I: Congestion Charging Zone

题目描述
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 :, 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.

分析:在7:30到19:00中找到最大值和最小值,注意可能只有一个数,那他就即是最大也是最小值。然后输出对应表格的金额即可。

#include <cstring>
#include <algorithm>
#include <cstring>
using namespace std;
int n,i,j,k,sum=0,vc[101],m,s,h;
int a630=6*60+30,a1000=10*60,a1600=16*60,a1900=19*60;//每个时间分割点的对应数值
int kai=0,mo=0;
int zhuanhuan(int h,int m)//时间转换函数
{
 int a;
 a=h*60+m;
 return a;
}
int main(void)
{
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  scanf("%d:%d",&h,&m);
  vc[i]=zhuanhuan(h,m);
 }
 sort(vc,vc+n);
 for(i=0;i<n;i++)//从前往后,找到第一个点,并且记录相应的时间区域
 {
  if(vc[i]<=a1000&&vc[i]>=a630){
   kai=1;break;}
  else if(vc[i]<=a1600&&vc[i]>a630){
   kai=2;break;}
  else if(vc[i]<=a1900&&vc[i]>a1600){
   kai=3;break;}
 }
 for(i=n-1;i>=0;i--)//从后往前,找到第一个点,并且记录相应的时间区域
 {
  if(vc[i]<=a1000&&vc[i]>=a630){
   mo=1;break;}
  else if(vc[i]<=a1600&&vc[i]>a630){
   mo=2;break;}
  else if(vc[i]<=a1900&&vc[i]>a1600){
   mo=3;break;}
 }
 if(kai==1&&mo==1)
  sum=24000;
 else if(kai==1&&mo==2)
  sum=24000;
 else if(kai==1&&mo==3)
  sum=36000;
 else if(kai==2&&mo==2)
  sum=16800;
 else if(kai==2&&mo==3)
  sum=24000;
 else if(kai==3&&mo==3)
  sum=24000;
 printf("%d",sum);
 return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值