Ryan_jiang07 @ 2021-07-26 14:58:49
本人第一次发帖子 蒟蒻求助ing
我下载了一组样例, 92200229 92200229
他说read0 expected1
结果我本地测出来输出是1没毛病
还请大佬康康我哪里有问题 本新人感激不尽!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll d1,d2;
bool isRun(ll x){
x/=10000;
if(x%400==0) return 1;
if(x%4==0&&x%100!=0) return 1;
return 0;
}
bool isValid(ll x){
x%=10000;
ll m=x/100,d=x%100;
if(m<1||m>12) return 0;
if(d<1||d>31) return 0;
if(m==4||m==6||m==9||m==11)//这些月30天
if(d>30) return 0;
if(m==2){
if(isRun(x))
if(d>29) return 0;
else
if(d>28) return 0;
}
return 1;
}
int main(){
cin>>d1>>d2;
ll l=d1/10000,r=d2/10000;
ll ans=0;
for(ll i=l;i<=r;i++){
ll j=i;
ll tmp=i*10000;
tmp+=(j/1000*1);
j%=1000;
tmp+=(j/100*10);
j%=100;
tmp+=(j/10*100);
j%=10;
tmp+=(j*1000);
if(tmp<d1||tmp>d2) continue;
if(isValid(tmp)) ans++;
}
cout<<ans<<endl;
return 0;
}
by sssom @ 2021-07-26 15:09:34
先构造回文,具体就是先枚举年份,然后构造,
by sssom @ 2021-07-26 15:11:02
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int runnian(int x)
{
if(x%4==0&&x%100!=0)return 1;
else if(x%400==0)return 1;
else return 0;
}
int truedate(int x)
{
int year=x/10000,month=(x/100)%100,day=x%100;
if(month==0||month>12)return 0;
if((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&&day>31)return 0;
if((month==4||month==6||month==9||month==11)&&day>30)return 0;
if(!runnian(year)&&month==2&&day>28)return 0;
if(runnian(year)&&month==2&&day>29)return 0;
return 1;
}
int main()
{
int x,y,sum=0;cin>>x>>y;int x1=x/10000,y1=y/10000;
for(int i=x1;i<=y1;i++)
{
int n=i*10000+i%10*1000+i%100/10*100+i%1000/100*10+i/1000;
if(truedate(n)&&n>=x&&n<=y)sum++;
}
cout<<sum;
return 0;
}
by sssom @ 2021-07-26 15:11:36
正常人都看得懂
by Ryan_jiang07 @ 2021-07-26 15:25:04
em,你代码我倒是看懂了,我感觉我大体思路和你一样 问题只是不知道我代码哪里导致本地和提交不一致
by Ryan_jiang07 @ 2021-07-26 21:58:02
好了没事了 我刚刚把原来代码又交了一遍结果对了 可能是洛谷的问题。。。