2018四川省大学程序设计竞赛(ACM) E: Ever17 ----------------------C语言——菜鸟级

Description
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.

Input
The first line contains an integer T
T
representing 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”.
1≤T≤5
1≤T≤5

Output
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.

Sample Input

Raw

3
02/07/19
19/02/07
07/02/19

Sample Output

Raw

6047
February 7, 2019
4516

Hint
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.

重在细节!!!!!!

AC代码

#include <stdio.h>
#include <string.h>
int T,aa,bb,cc,flag1,flag2;
int p[13]={29,31,28,31,30,31,30,31,31,30,31,30,31};
int pdrn(int yy)//闰年判断 
{if((yy%4==0&&yy%100!=0)||yy%400==0)return 1;
 else return 0;
}
int gs1()//判断 是否 符合 格式 1  MM/DD/YY 
{ int yy=cc+2000;p[2]=28;
    if(pdrn(yy))p[2]=p[0];
    if(aa>12||aa==0)return 0;
    if(bb>p[aa]||bb==0)return 0;
    return 1;
}
int gs2()//判断 是否 符合 格式 2  YY/MM/DD 
{ int yy=aa+2000;p[2]=28;
    if(pdrn(yy))p[2]=p[0];
    if(bb>12||bb==0)return 0;
    if(cc>p[bb]||cc==0)return 0;
    return 1;
}
int tsc()//求天数差  =(起始年到目标日期-起始年到起始日期)  
{      
    int y1=aa+2000,m1=bb,d1=cc,y2=cc+2000,m2=aa,d2=bb,ans=0,i,sum=0;
      //y1 m1 d1 为起始日期    y2 m2 d2 为目标日期 
    if(aa>cc)y1=cc+2000,m1=aa,d1=bb,y2=aa+2000,m2=bb,d2=cc;//较大的日期作为目标日期 
    p[2]=28;//默认 2月为平年 
    if(pdrn(y1))p[2]=29;//若为闰年 附值为29 
    for(i=1;i<m1;i++)//计算 起始年(XXXX年1月1日) 到 起始日期的天数 
        sum+=p[i];
        sum+=d1;
    while(y1<y2)//以年为单位在增加 
    {
        if(pdrn(y1))ans+=366;
        else ans+=365;
        y1++;
    }
    p[2]=28;
    if(pdrn(y2))p[2]=p[0]; 
    for(i=1;i<m2;i++)//以月为单位增加 
        ans+=p[i];
        ans+=d2;//天数增加 
        return ans-sum;//(起始年到目标日期-起始年到起始日期) 
}
int main()
{  char yue[12][20]={"January","February","March","April","May","June","July","August","September","October","November","December"};
    scanf("%d",&T);
    while(T--)
    {   
        scanf("%d/%d/%d",&aa,&bb,&cc);
        flag1=gs1();
         flag2=gs2();
        if(flag1&&flag2)
        {
         if(aa==bb&&bb==cc)printf("%s %d, %d\n",yue[aa-1],bb,2000+cc);
         else 
        {int ans=tsc();if(ans<0)ans=-ans;//01/03/01同一年的情况可能为负 
            printf("%d\n",ans);
        }
        }else
        {   if(flag2)printf("%s %d, %d\n",yue[bb-1],cc,2000+aa);
            else printf("%s %d, %d\n",yue[aa-1],bb,2000+cc);
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Five-菜鸟级

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值