ZCMU-1800-Demerit Points

1800: Problem D: Demerit Points

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 4   Solved: 3
[ Submit][ Status][ Web Board]

Description

Problem D: Demerit Points

A province to our west, which shall remain nameless, but whose name does not start with A, B, or S, has a unique system for driver's license demerit and merit points. The system works (more or less) as follows.

A new driver starts with no merit or demerit points. When the driver is convicted of a driving offense, he or she is given between 2 and 15 demerit points, depending on the severity of the offense.

A merit point is given, to a maximum of five, for each interval of two years in which a driver has no offenses and no demerit points. Each merit point cancels up to two demerit points. If a subsequent offense occurs and the number of demerit points exceeds double the number of merit points, the number of demerit points is reduced by double the number of merit points, and the number of merit points is set to 0. If a subsequent offense occurs and the number of demerit points is less than or equal to double the number of merit points, the number of demerit points is reduced to 0, and the number of merit points is reduced by half the number of demerit points. Any fractional merit points are discarded.

Demerit points are reduced whenever a driver has one year free of any driving offense. This reduction decreases the number of demerits by half or by 2, whichever is more. Any fractional or negative demerit points are discarded. This reduction takes place on each anniversary of the most recent offense until no points remain.

If a new offense occurs on the same day as a demerit point reduction or merit point award, the reduction/award is done before the new demerit points are given.

Your job is to read a set of information records for a driver, and to print the number of merit or demerit points at any given time.

The first line of input contains the date of issue of the license (yyyymmdd) Subsequent lines contain information on offenses, in chronological order. Each such line contains the offense date (yyyymmdd) and the number of points applied (an integer between 2 and 15). On the day the license is issued, and on every occasion that the number of merit or demerit points changes, output a line giving the date and the number of points, in the format below. Output terminates when 5 merit points are accumulated following the last offense.

Input

Output

Sample Input

19820508
19830606 2
19830607 2
19891212 15

Sample Output

1982-05-08 No merit or demerit points.
1983-06-06 2 demerit point(s).
1983-06-07 4 demerit point(s).
1984-06-07 2 demerit point(s).
1985-06-07 No merit or demerit points.
1987-06-07 1 merit point(s).
1989-06-07 2 merit point(s).
1989-12-12 11 demerit point(s).
1990-12-12 5 demerit point(s).
1991-12-12 2 demerit point(s).
1992-12-12 No merit or demerit points.
1994-12-12 1 merit point(s).
1996-12-12 2 merit point(s).
1998-12-12 3 merit point(s).
2000-12-12 4 merit point(s).
2002-12-12 5 merit point(s).
【解析】
这道题就是给你一个起始时间,再给你其他时间和扣的分,如果在一年当中没有扣分的话,就让扣的分减去max(2,demerit/2)
如果扣的 分为0,那就让merit加1,merit可以抵2分,比如说拥有两个merit,而扣了15分,这个时候分数一抵就变成了11分了
如果最后输入的还是扣分的,只要有merit并且还扣的分就要用merit来抵消就算是只扣1分也要抵消,或者,merit不到5就每
两年输出一次。merit加上1.在输入结束的时候merit都要置0,从0开始。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
int year,month,day,mer,demer;
void facs(int n)
{
   year=n/10000;//计算年份月份日子
   n%=10000;
   month=n/100;
   day=n%100;
}
int main()
{
    int n,m,k;
    scanf("%d",&n);
    k=n;
    facs(k);
     printf("%04d-%02d-%02d No merit or demerit points.\n",year,month,day);//先输出最开始的
    while(~scanf("%d%d",&n,&m))
    {
        int count1=0;
        for(k+=10000;k<=n;k+=10000)//从K日期开始到n结束
        {
            if(demer>0)
            {
                demer-=max(2,int(demer+1)/2);//
                facs(k);
                if (demer>0) printf("%04d-%02d-%02d %d demerit point(s).\n",year,month,day,demer);
                else
                {
                    demer=0;
                    printf("%04d-%02d-%02d No merit or demerit points.\n",year,month,day);
                }
            }
            else
            {
                if (count1%2!=0)//count1从0开始,变成1的时候代表已经第二年是demerit为0了
                {
                    mer++;
                    facs(k);
                    printf("%04d-%02d-%02d %d merit point(s).\n",year,month,day,mer);
                }
                count1++;
            }
        }
            k=n;
            demer+=m;
            facs(k);
            if (mer)//如果merit不为零就可以抵消demerit
           {
            while (demer>0 && mer>0)
                mer--,demer-=2;//并且要清空merit为0
            mer=0;
           }
        if (mer>0)
            printf("%04d-%02d-%02d %d merit point(s).\n",year,month,day,mer);
        if (demer>0)
            printf("%04d-%02d-%02d %d demerit point(s).\n",year,month,day,demer);
        if (demer==0 && mer==0)
            printf("%04d-%02d-%02d No merit or demerit points.\n",year,month,day);
    }
    while (demer!=0)
    {
        k+=10000;
        facs(k);
        demer-=max(2,(int)((demer+1)/2));
        if (demer>0) printf("%04d-%02d-%02d %d demerit point(s).\n",year,month,day,demer);
        else
        {
            demer=0;
            printf("%04d-%02d-%02d No merit or demerit points.\n",year,month,day);
        }
    }
    for (mer=0;mer<6;mer++)//从0开始
    if (mer)
    {
        k+=20000;
        facs(k);
        printf("%04d-%02d-%02d %d merit point(s).\n",year,month,day,mer);
    }
    return 0;
    }

### 回答1: zcmu 1093 简单计算器是一道编程题目,要求实现一个简单的计算器,能够进行加、减、乘、除四种基本运算。该题目主要考察编程基础能力和算法思维能力,需要熟练掌握基本的运算符和控制语句,能够设计合理的算法实现计算器功能。 ### 回答2: zcmu 1093 简单计算器是一种基于计算机技术的工具,用于进行基本算术运算,如加减乘除等。它能够简化我们在日常生活中的计算工作,提高计算效率,减少出错率。 使用zcmu 1093 简单计算器非常简单,只需输入需要计算的数字和符号,就能够得到计算结果。它可以进行多个数字之间的复杂运算,同时还支持小数、百分数、平方根等复杂运算。另外,zcmu 1093 简单计算器还可以存储中间计算结果,方便我们进行多步计算或调整计算过程。 除了日常的计算工作,zcmu 1093 简单计算器还可用于科学计算、工程设计等领域。许多专业软件都是基于简单计算器原理设计的,它们具有更高的计算精度和更复杂的运算能力,能够支持更高级别的科学计算和技术分析。 总之,zcmu 1093 简单计算器在日常生活中有着广泛的应用,它使我们的计算工作变得更加高效、准确。并且,随着科技的不断发展,这种计算工具也在不断地更新和改进,为我们的计算工作提供更加便捷、多样化的选择。 ### 回答3: ZCMU 1093 简单计算器是一道基础的算法题目,需要实现一个简单的计算器程序,支持加、减、乘、除四种基本运算,可以对两个整数进行运算并输出结果。 要实现这道题目,首先需要根据输入的运算符来判断应该进行的运算类型,并根据运算符的不同,执行不同的计算操作。同时,应注意除数不能为零的情况,避免程序出现异常。 在编写程序的过程中,可以使用 switch case 语句来判断不同的运算类型,并执行相应的计算操作。同时,为了能有效地判断输入的运算符,可以使用输入字符串的方式进行处理,提取出运算符进行比较。 此外,在程序中还需要进行合法性判断,确保输入的数字均为整数且在合理的范围内,以避免程序运行出现异常情况。同时,还需要考虑输入格式的问题,应确保输入的数字和运算符符合题目要求。 综上所述,ZCMU 1093 简单计算器是一道基础的算法题目,需要实现一个简单的计算器程序,支持加、减、乘、除四种基本运算,注意程序的合法性判断和输入格式的处理,能够熟练地运用 switch case 等语句完成程序的编写。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值