sicily 1202. The Bank of Kalii

1202. The Bank of Kalii

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

Customers of the Bank of Kalii handle their banking transactions similar to the way they handle their taxes: be as terse as possible. As a result, when a customer writes a check or fills out a deposit or withdrawal form, they leave off the year on any date they write down. So, instead of writing: 09/20/2005, they would write: 9/20 and be done with it. In general, the year can be inferred since it will be relatively close to the date the transaction is actually processed by the bank.

Without going into the intricate details of how the Bank of Kalii calculates interest and banking fees (that is a problem for another time...), suffice to say the bank must determine the actual date the customer wrote on the check or form, and calculate the number of days prior (or in the future) the document is dated. You see, Kaliian bankers, like their government officials, are overworked, so they may not get around to processing transactions for up to a week. The customers know this, so they often date their checks and forms a several days in the future - this complicates the bankers' duties as well.

Your job is to write a program to compare a date written on a check or form with the date the transaction is being processed, and, determine the full date the customer meant as well as how many days prior (or in the future) the document is dated.

Input

The first line of input contains an integer N which is the number of datasets that follow (1$ \le$N$ \le$1000) . Each dataset consists of a single line containing two dates: the transaction date and the document date; there is a single space between them. The transaction date is of the form M/D/Y where M is the month number (1$ \le$M$ \le$12) , D is the day of month (1$ \le$D$ \le$md1) and Y is the year (2000$ \le$Y$ \le$2200) . The document date is of the form m/d where m is the month number (1$ \le$m$ \le$12) and d is the day of month (1$ \le$d$ \le$md2) . The values of md1 and md2 will not exceed the number of days in the respective months M and m .

Output

For each dataset print out the dataset number followed by a space followed by the result of the date comparison as shown in the table below:

Result to printCriteria
m/d /y IS n DAY(S) PRIORIf the document date occurs before the
 transaction date and is within 7 days in the past
m/d /y IS n DAY(S) AFTERIf the document date occurs after the transaction
 date and is within 7 days in the future
SAME DAYIf the dates are the same.
OUT OF RANGEAll other results not with +/- 7 days.

 

 


Notes: When printing the result date, m/d /y , you will have to determine the year value y (1999$ \le$y$ \le$2201) . This is not necessarily the same as the transaction date's year value Y . Since the Kalii taxation fiasco a couple of years back, the Kaliian government decided to switch to the standard Gregorian calendar. As such, Gregorian leap year rules apply. A year is a leap year (February has 29 days instead of 28) if the year if evenly divisible by 4, except for century years (those ending in 00), which are leap years only if they are evenly divisible by 400. 2000 and 2004 are leap years, but 2100 and 2101 are not. For those who do not know, the months of January, March, May, July, August, October and December all have 31 days in them. February has 28 days (unless in a leap year, then it has 29). The remainder of the months has 30 days.

Sample Input

<P>
<PRE>
7 
11/20/2005 11/21 
11/20/2005 11/17 
11/20/2005 11/20 
11/20/2005 11/13 
11/20/2005 11/28 
1/2/2005 12/30 
12/31/2100 1/3
</PRE> 

Sample Output

<P>
<PRE>
1 11/21/2005 IS 1 DAY AFTER 
2 11/17/2005 IS 3 DAYS PRIOR 
3 SAME DAY
4 11/13/2005 IS 7 DAYS PRIOR 
5 OUT OF RANGE
6 12/30/2004 IS 3 DAYS PRIOR
7 1/3/2101 IS 3 DAYS AFTER
</PRE> 

题目分析

比较一个日期是否在另一个日期的前后一个星期内
直接暴力枚举第一个日期的前后一个星期的日期进行比对即可
考察日期的加一天和减一天
注意输出DAY还是DAYS


#include <stdio.h>

int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int Feb(int year) {
  if ( (year%4==0&&year%100!=0) || (year%400==0))
    return 29;
  return 28;
}

int ms, ds, ys, me, de;

bool searchBefore(int id) {
  int tempm = ms, tempd = ds, tempy = ys;
  for (int i = 1; i <= 7; ++i) {
    if (tempd >= 2) {
      tempd--;
    } else {
      if (tempm >= 2) {
        tempm--;
        tempd = month[tempm-1];
      } else {
        tempm = 12;
        tempy--;
        tempd = month[tempm-1];
      }
    }
    if (tempm == me && tempd == de) {
      printf("%d %d/%d/%d IS %d DAY", id, tempm, tempd, tempy, i);
      if (i > 1) printf("S");
      printf(" PRIOR\n");
      return true;
    }
  }
  return false;
}

bool searchAfter(int id) {
  int tempm = ms, tempd = ds, tempy = ys;
  for (int i = 1; i <= 7; ++i) {
    if (tempd != month[tempm-1]) {
      tempd++;
    } else {
      if (tempm == 12) {
        tempm = 1;
        tempd = 1;
        tempy++;
      } else {
        tempm++;
        tempd = 1;
      }
    }
    if (tempm == me && tempd == de) {
      printf("%d %d/%d/%d IS %d DAY", id, tempm, tempd, tempy, i);
      if (i > 1) printf("S");
      printf(" AFTER\n");
      return true;
    }
  }
  return false;
}


int main()
{
  int test;
  scanf("%d", &test);
  for (int id = 1; id <= test; ++id) {
    scanf("%d/%d/%d %d/%d", &ms, &ds, &ys, &me, &de);

    if (ms == me && ds == de) {
      printf("%d SAME DAY\n", id);
      continue;
    }

    month[1] = Feb(ys);
    if (searchBefore(id))
      continue;
    if (searchAfter(id))
      continue;

    printf("%d OUT OF RANGE\n", id);
  }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值