第十届四川省大学生程序设计竞赛

点击打开链接

E: Ever17

Time Limit: 1000 MS Memory Limit: 1048576 KB
Total Submit: 196 Accepted: 39 Page View: 573
Submit Status Clarify

As is known to all, we have two formats to denote a specific date: MM/DD/YY or YY/MM/DD. We supposed the years discussed below are years in 20YY.

Now you are given a string representing the date. If there is only one possible date it can fit in with format of "MM/DD/YY" or "YY/MM/DD", output the date in the format of "month date, year" (as can be seen in the second sample). Otherwise, output the days between the two different dates it might be.

The first line contains an integer Trepresenting the number of test cases.
In each test case, a string ”AA/BB/CC” is given in one line.
It is guaranteed that there is at least one legal date it can fit in with
format of ”MM/DD/YY” or ”YY/MM/DD”. 1T5
For each test case, if there are two different possible dates, output an integer in one line representing the days between the two possible dates. In the other case, output the exact date in one line.
3
02/07/19
19/02/07
07/02/19
6047
February 7, 2019
4516
In the first sample, the date might be July 19th, 2002 or February 7th, 2019. The number of days between the two dates are 6047 days.As for the second sample, the only possible date is February 7th, 2019.There are 12 months in a year and they are January, February, March, April, May, June, July, August, September, October, November and December.Also, please note that there are 29 days in February in a leap year while 28 days in nonleap year.


题意:

给一个合法的日期,可能是MM/DD/YY or YY/MM/DD,如果是其中的一种,则输出"month date, year",

否则,输出两个日期的差值,若差值为0,输出个日期

Otherwise, output the days between the two different dates it might be.

#include
using namespace std;
int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int leap_day[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
char month[13][10]={"","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November" ,"December"};
bool leap(int y)
{
    if(y%4==0&&y%100!=0||y%400==0)
        return 1;
    return 0;
}
bool check(int y,int m,int d)
{
    if(y<0||y>99)   return 0;
    if(m<1||m>12)   return 0;
    if(d<1||d>31)   return 0;
    if(leap(y+2000))
    {
        if(d>leap_day[m])   return 0;
    }
    else
        if(d>day[m])   return 0;
    return 1;
}
long long sum(int y,int m,int d)
{
    long long sum=0;
    for(int i=0;i



你可能感兴趣的:(第十届四川省大学生程序设计竞赛)