zoukankan      html  css  js  c++  java
  • 短代码.第几天

    给定一个日期,输出这个日期是该年的第几天。输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成。对于每组输入数据,输出一行,表示该日期是该年的第几天。
    比如
    1985/1/20
    2006/3/12
    输出
    20
    71
    main(y,m,d){while(scanf("%d/%d/%d",&y,&m,&d)==3){char s[]={0,1,-1,0,0,1,1,2,3,3,4,4};m--;d+=m*30+s[m],(y%400==0||y%100&&y%4==0)&&m>1&&d++;printf("%d\n",d);}}

    int s[]={0,1,-1,0,0,1,1,2,3,3,4,4};main(y,m,d){for(;~scanf("%d/%d/%d",&y,&m,&d);printf("%d\n",d+m*30+s[m]+!((y%400&&0==y%100||y%4)||m<2)))m--;}

    int s[]={0,1,-1,0,0,1,1,2,3,3,4,4};main(y,m,d){for(;~scanf("%d/%d/%d",&y,&m,&d);printf("%d\n",d+m*30+s[m]+!(y%400&&0==y%100||y%4||m<2)))m--;}

    int s[]={0,1,-1,0,0,1,1,2,3,3,4,4};main(y,m,d){for(;~scanf("%d/%d/%d",&y,&m,&d);printf("%d\n",d+m*30+s[m]+!(y/100%4||y%4||m<2)))m--;}

    int s[]={0,1,-1,0,0,1,1,2,3,3,4,4};main(y,m,d){for(;~scanf("%d/%d/%d",&y,&m,&d);printf("%d\n",d+m*30+s[m]+!(y/100%4+y%4||m<2)))m--;}

    main(y,m,d)
    {for(;~scanf("%d/%d/%d",&y,&m,&d);printf("%d\n",d+m*30+"bcabbccdeeff"[m]-'b'+!(y/100%4+y%4||m<2)))m--;}

    main(y,m,d)
    {for(;~scanf("%d/%d/%d",&y,&m,&d);printf("%d\n",d+m*30+"BCABBCCDEEFF"[m-1]-96+!(y/100%4+y%4||m<3)));}


    main(y,m,d)
    {for(;~scanf("%d/%d/%d",&y,&m,&d);printf("%d\n",d+m*30+"XBCABBCCDEEFF"[m]-96+!(y/100%4+y%4||m<3)));}

    main(y,m,d)
    {for(;~scanf("%d/%d/%d",&y,&m,&d);printf("%d\n",d+m*30+"XBCABBCCDEEFF"[m]-95-(y/100%4+y%4||m<3)));}
    不多解释了...

    也许这里只有y/100%4+y%4判断是否是闰年有点价值吧...
  • 相关阅读:
    查看python关键字
    命令终端执行python
    Codeforces-462C. A Twisty Movement
    Codeforces-462A. A Compatible Pair
    Codeforces-446C. Pride
    Codeforces-Hello 2018C. Party Lemonade(贪心)
    Codeforces-33C. Wonderful Randomized Sum
    Codeforces-118D. Caesar's Legions(lazy dynamics)
    codeforces-73C. LionAge II
    Gym 101510C-Computer Science
  • 原文地址:https://www.cnblogs.com/kaikai/p/823190.html
Copyright © 2011-2022 走看看