3275. 章鱼哥没有日历

Fifnmar

其实吧,这道题应该是想让大家练习列表……

编程一定要数据和逻辑分离啊……

unsigned const months[13]{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

这样写不就清爽了嘛~

CCXXXI_

A pythonic answer:

from datetime import date
try:
    today = date(*map(int,input().split('-')))
    print((today - date(2017,1,1)).days + 1)
except ValueError:
    print(-1)

If you really hate import, you can search for datetime.py in your computer, read it, then define the class date by yourself. :)

Fifnmar

我今天发现,C++ 的 <iomanip> 里也有个读取时间的东西 get_time,233333

CCXXXI_

然而这样读完之后并不能直接加减运算,想做到类似的事还得等c++20实装chrono::year_month_day ㄟ( ▔, ▔ )ㄏ

Fifnmar

太难了233

功夫橘猫

疯狂的代码

include

int main()
{
int month,day;
int sum=0,i;
int da[12]={31,28,31,30,31,30,31,31,30,31,30,31};
scanf(“2017-%d-%d”,&month,&day);
for(i=0;i=1&&(month==1&&day<=31||month==2&&day<=28||month==3&&day<=31||month==4&&day<=30||month==5&&day<=31||month==6&&day<=30||month==7&&day<=31||month==8&&day<=31||month==9&&day<=30||month==10&&day<=31||month==11&&day<=30||month==12&&day<=31))
printf(“%d\n”,sum);
else
printf(“-1\n”);
}

thesomeway1

include “stdio.h”

int main()
{
int a,b,c;
scanf(“%d-%d-%d”,&a,&b,&c);
if(b>=1&&b<=12&&c>0)
{
switch(b)
{
if(b==01&&c<=31)
case 01:printf(“%d”,c);
else
{
printf(“-1”);
} break;
if(b==02&&c<=29)
case 02:printf(“%d”,c+31);else
{
printf(“-1”);
} break;
if(b==03&&c<=31)
case 03:printf(“%d”,c+59); else
{
printf(“-1”);
}break;
if(b==04&&c<=30)
case 04:printf(“%d”,c+90); else
{
printf(“-1”);
}break;
if(b==05&&c<=31)
case 05:printf(“%d”,c+120); else
{
printf(“-1”);
}break;
if(b==06&&c<=30)
case 06:printf(“%d”,c+151); else
{
printf(“-1”);
}break;
if(b==07&&c<=31)
case 07:printf(“%d”,c+181); else
{
printf(“-1”);
}break;
if(b==8&&c<=31)
case 8:printf(“%d”,c+212); else
{
printf(“-1”);
}break;
if(b==9&&c<=30)
case 9:printf(“%d”,c+243); else
{
printf(“-1”);
}break;
if(b==10&&c<=31)
case 10:printf(“%d”,c+273); else
{
printf(“-1”);
}break;
if(b==11&&c<=30)
case 11:printf(“%d”,c+304); else
{
printf(“-1”);
}break;
if(b==12&&c<=31)
case 12:printf(“%d”,c+334); else
{
printf(“-1”);
}break;
default:printf(“-1”);
}
}
else
{
printf(“-1”);
}
return 0;
}为啥回答错误

你当前正在回复 博客/题目
存在问题!