lilili1024 @ 2022-08-25 17:45:11
#include<bits/stdc++.h>
using namespace std;
long long day[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int main(){
long long r,m,ans;
cin>>r>>m;
for (int i=1;i<=12;i++)
{
for (int w=1;w<=day[i];w++)
{
int j=(w%10)*1000+(w/10)*100+(r%10)*10+r/10;
int date=j*10000+r*100+w;
ans +=(date>=r&&date<=m);
}
}
cout<<ans<<endl;
return 0;
}
dalao求解QwQ
by liuhongcheng2013 @ 2022-08-25 17:50:21
能不要用万能头文件吗?
by Cczzyy20150005 @ 2022-08-25 17:52:13
@liuhongcheng2013
万能头对于新手来说比较好用
by liuhongcheng2013 @ 2022-08-25 17:55:38
因为万能头文件里的一些函数名你可能不知道,在定义变量名就可能定义成函数名 比如万能头文件里有个函数叫“time”,经常求时间的时候就会用到“变量类型 time;”
by TempestJueMu @ 2022-08-25 17:56:20
@lilili1024 day
数组下标默认从0开始。
by TempestJueMu @ 2022-08-25 17:57:27
@liuhongcheng2013 我寻思这代码里也没有撞函数名啊,而且撞了会报错的。
by lilili1024 @ 2022-08-25 18:00:57
@Guolar_JueMu 通过了!谢谢dalao!
by liangbowen @ 2022-08-25 18:08:37
@liuhongcheng2013 这个是个人习惯问题。虽然不用万能头的确更好,但用万能头的人也不在少数
by _Cppsteve_ @ 2022-08-25 18:30:29
好习惯:初始化 ans=0
。
by Wangyunzhe1688 @ 2022-10-07 20:28:52
#include<bits/stdc++.h>
using namespace std;
int f(int x){
int sum=0;
while(x){
sum=sum*10+x%10;
x/=10;
}return sum;
}
bool year(int y1){
if((y1%4 == 0&&y1%100 != 0)||y1%400 == 0){
return true;
} else {
return false;
}
}
bool month1(int m1){
if(m1>=1&&m1<=12) return true;
else return false;
}
bool day1(int m1,int y1,int d1){
if(m1 == 1||m1 ==3||m1 ==5||m1 ==7||m1 ==8||m1 ==10||m1 ==12) {
if(d1<=31&&d1>=1) return true;
else return false;
}
if(m1 ==4||m1 ==6||m1 ==11||m1 ==9){
if(d1<=30) return true;
else return false;
}
if(m1 == 2){
if(year(y1)){
if(d1<=29){
return true;
}else{
return false;
}
}else{
if(d1<=28){
return true;
}else{
return false;
}
}
}
}
int main(){
int y1,m1,d1,y2,m2,d2,cnt = 0;
scanf("%4d%2d%2d\n%4d%2d%2d",&y1,&m1,&d1,&y2,&m2,&d2);
for(int i = y1;i<=y2;i++){
int date = i*10000+f(i);
int month=date/100%100,day=date%100;
if(month1(month)&&day1(month,i,day)&& date >=y1*10000+m1*100+d1&&date<=y2*10000+m2*100+d2){
cnt++;
}
}
cout<<cnt;
return 0;
}
by Wangyunzhe1688 @ 2022-10-07 20:29:32
可以参考一下