8 条题解
-
4
【解析】使用列表 存储每个月的天数,列表的索引就表示月份,例如 ,就表示1月有31天。
根据这样的算法思想,不确定的就是2月的天数。可以先将2月的天数初始化为28,在输入年和月后,判断一下是否为闰年,若是,则将 的值修改为29。
最后输出 就是某年某月的天数。参考代码如下:day=[0,31,28,31,30,31,30,31,31,30,31,30,31] year,month=map(int,input().split()) if year%100!=0 and year%4==0 or year%400==0: day[2]=29 print(day[month])
-
2
#include <iostream> #include <cstdio> using namespace std; int days[12]={31,28,31,30,31,30,31,31,30,31,30,31}; int isleap(int y){ if((y%4000)|| (y%40 && y%100!=0)){ return 1;}else{ return 0;} } int main() { int year,mouth; cin>>year>>mouth; days[1]+=isleap(year); cout<<days[mouth-1]<<endl; return 0; }
-
1
last update:2023/4/2
就只是考if语句的运用而已
year=int(input()) date=int(input()) if date==1 or date==3 or date==5 or date==7 or date==8 or date==10 or date==12 : print(31) elif date!=2: print(30); else: if year%400==0: print(29) elif year%4==0 and year%100!=0: print(29) else: print(28)
未维护的正常分支写法
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c; cin>>a>>b; if(b==1||b==3||b==5||b==7||b==8||b==10||b==12){ cout<<"31"; } if(b==4||b==6||b==9||b==11){ cout<<"30"; } if(b==2){ if(a%4==0&a%100!=0){ cout<<"29"; } if(a%100==0){ if(a%400==0) cout<<"29"; if(a%400!=0) cout<<"28"; } if(a%4!=0){ cout<<"28"; } } return 0; }
- 1
信息
- ID
- 24
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 6
- 标签
- 递交数
- 3125
- 已通过
- 874
- 上传者